Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

CavemanUK

macrumors 6502
Original poster
Jun 29, 2006
456
69
Rhyl, North Wales
Hi, lets say i have 3 tables set out like this....

tbl_Customers
-------------
id
CustomerName
customertype_id
customerreferrer_id

tbl_CustomerTypes (eg.. Private, Contract etc)
------------------
id
Type

tbl_CustomerReferrers (eg.. Word of Mouth, Advertising etc)
---------------------
id
Referrers


How would i send a query that pulls an array with the following fields..

CustomerName CustomerType CustomerReferrer
Jones Contract Newspaper Advert
Smith Private Word of Mouth

etc

hope this makes sense.
 
As has been said, have a look at JOINS.

Although this could be putting my SQL skills at risk I thought I'd try and post my first helpful post rather than asking questions, the following should do what you want:

PHP:
SELECT CustomerName, Type AS CustomerType, Referrer AS CustomerReferrer
FROM tbl_Customers
LEFT JOIN tbl_CustomerTypes ON tbl_Customers.customertype_id = tbl_CustomerTypes.id
LEFT JOIN tbl_CustomerReferrers ON tbl_Customers.customerreferrer_id = tbl_CustomerReferrers.id
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.