Page 1 of 1

mysql php join table problem

Posted: Tue Feb 03, 2009 10:27 am
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.

Re: mysql php join table problem

Posted: Tue Feb 03, 2009 10:30 am
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]