PDA

View Full Version : how to show name of table from foreign key rather than id


nanny
07-06-2007, 01:38 AM
Hi if I am showing search results - how to show the table name rather than foreign key id that was in table.
e.g. listing table has its own id but then has industryid, categoryid, locationid that are foreign keys from another table.
Where I place the search results I don't want a number of the table but the name. Here is what I have for one search:


SELECT *
FROM listing
WHERE listing.listingID = '%SearchString%' OR listing.classtypeid = '%SearchString%' OR listing.classbusinessname = '%SearchString%' OR listing.inv_addr1 = '%SearchString%' OR listing.inv_addr2 = '%SearchString%' OR listing.inv_state = '%SearchString%' OR listing.inv_zip = '%SearchString%' OR listing.tel = '%SearchString%' OR listing.contactphone2 = '%SearchString%' OR listing.contactfax = '%SearchString%' OR listing.classcatid = '%SearchString%' AND listing.status = 'active' AND listing.paystatus = 'unpaid'

the listing.classcatid is one foeign key as an example, there are a few.
If I do a search it comes up as a number, do I somehow do a join???

Thanks I really need to know this....
Should I change the table to have a name as the foreign key rather than a number???
Thanks

davidj
07-06-2007, 10:32 AM
your wanting to join two tables together???