I've 2 tables.

first,cardb

ID,vehicle,engine,gear

second,labels

ID,label,value

what i have to do is, say with this record

cardb:1,punto,3500cc,auto

if i wish to display this row to customers, i actually do:

mysql_query(Select * from cardb WHERE ID=1);
foreach($field as $value)SELECT label FROM labels WHERE value='$value';

After which display labels(easy to use version of worth saved in db) to user.

my real question is, it is possible to method to link the values of fields in cardb using its corresponding in labels table without needing to do 2 query ??

Illustration of Cardb

  • ID:vehicle:engine:gear
  • 1:Picanto:1100cc:Auto

Illustration of labels

  • label:ID:Value:label
  • label:1:1100cc:'1100 Engine capacity (cc)'
  • label:2:Manual:'Automatic transmition'

GOAL seach for label of every cardb area in labels table and show it

Therefore the only outcomes of your tables would be that the value area of lables consists of an extended version from the text within the area label, which shorter versions are utilized within the cardb, within the area vehicle, engine and gear. And you need a question locating this content of cardb, however with the lengthy versions from the labels in vehicle, engine and gear rather than rapid which are really within the table. The query you'll need will be:

SELECT c.ID,l1.value car,l2.value engine,l3.value gear FROM cardb c
LEFT OUTER JOIN labels l1 on c.car=l1.label
LEFT OUTER JOIN labels l2 on c.engine=l2.label
LEFT OUTER JOIN labels l3 on c.gear=l3.label;

You can test something similar to

mysql_query(Select * from cardb,labels WHERE cardb.ID=labels.value);

If you're able to stay away from the * and poll specific posts it's suggested.