Jump to content

[SOLVED] php select multiple tables from mysql


tommy445

Recommended Posts

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.