tommy445 Posted March 20, 2009 Share Posted March 20, 2009 I am querying data from multiple tables. I've got it to do it however it is displaying data that it shouldn't. my php query is wrong. Below is my setup and result. Please Help. table1 service_contact [10,10,11] service_date [236837600,236837600,236837600] service_name [staff1,staff2,staff3] table2 clinet_id [10,11,12] client_name [john doe,mary jane,tim tom] client_address [dc,tx,fl] table 1 Service_contact and table 2 clinet_id are in relation ----My query is 10 $sel = "select * from table1, table2 where table1.service_contact and table2.client_id='".$_POST['client_id']."'"; $run = mysql_query($sel) or die(mysql_error()); if(mysql_num_rows($run)>0) { ?> Display Code <?php echo $row['client_name']; ? <?php $service_date = $row ['service_date']; echo date('F d, Y', $service_date)?> <?php $service_name = $row['service_name']; echo $service_name;?> ----------- Result John Doe February 26, 2009 Staff1 John Doe February 26, 2009 Staff2 John Doe February 26,2009 Staff3 ---- John Doe should be the only result with two entries from Staff 1 & 2 which is correct. However staff three is being displayed which it shouldn't, more over it is wrong because staff3 entry is for Mary Jane which is 11. please help. Link to comment https://forums.phpfreaks.com/topic/150255-solved-php-select-multiple-tables-from-mysql/ Share on other sites More sharing options...
Floydian Posted March 20, 2009 Share Posted March 20, 2009 $sel = "select *.t2, *.t1 from table2 as t2 left join table1 as t1 on t2.client_id = t1.service_contact where t2.client_id='".$_POST['client_id']."'"; $run = mysql_query($sel) or die(mysql_error()); Hope that helps... Link to comment https://forums.phpfreaks.com/topic/150255-solved-php-select-multiple-tables-from-mysql/#findComment-789077 Share on other sites More sharing options...
tommy445 Posted March 20, 2009 Author Share Posted March 20, 2009 thank you! Link to comment https://forums.phpfreaks.com/topic/150255-solved-php-select-multiple-tables-from-mysql/#findComment-789101 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.