mysql php join table problem

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
kitaeshi
Forum Newbie
Posts: 4
Joined: Fri Jan 30, 2009 12:13 am

mysql php join table problem

Post by kitaeshi »

Hi i have 2 table

customers table
userID
name

appointment table
appointmentID
userID


i need to display out the appointment table where by the appointment.userID is displaying the customers.name instead using php code..i try running

Code: Select all

 
$query=("SELECT appointment.userID, customers.userID, customers.name FROM appointment LEFT JOIN customers ON appointment.userID = customers.userID");
$result=mysql_query($query);
 
while($row = mysql_fetch_array($result)){
    echo $row['userID']. " - ". $row['name'];
    echo "<br />";
}
 
 
but it doesn't work...anyone can advise me how to get about doing it?
Thanks.
User avatar
VladSun
DevNet Master
Posts: 4313
Joined: Wed Jun 27, 2007 9:44 am
Location: Sofia, Bulgaria

Re: mysql php join table problem

Post by VladSun »

You don't need both appointment.userID and customers.userID - they have the same values. What's worse - they have name collision in $row['userID']. Try removing one of it from the select or use an alias:
[sql]... appointment.userID AS a_uid, customers.userID AS c_uid,[/sql]
There are 10 types of people in this world, those who understand binary and those who don't
Post Reply