[thelist] php/mysql - two consecutive select statements

noah noah at tookish.net
Fri Nov 16 02:41:50 CST 2001

I'm having a problem with select statements (PHP querying MySQL).

There are 2 statements in a row:

$job_query = mysql_query("SELECT client_id FROM table1 WHERE id = $job_id");
list($client_id) = mysql_fetch_row($job_query);

$client_query = mysql_query("SELECT table2.client_name, table3.givenname, 
table3.surname, table3.email FROM table2, table3 WHERE table2.consultant = 
table3.id AND table2.id = $client_id");
list($client_name, $client_consultant_givenname, 
$client_consultant_surname, $client_consultant_email) = 

For some reason, if the first select is there, the second doesn't work - as 
soon as I take the first out (e.g., replace it with just "$client_id = 
2;"), the second select works fine.

(In case this is relevant, the two selects above are the second and third 
of three in a row - the first is:

$candidate_query = mysql_query("SELECT table4.givenname, table4.surname, 
table3.givenname, table3.surname, table3.email FROM table4, table3 WHERE 
table4.consultant = table3.id AND table4.id = $candidate_id");

list($candidate_givenname, $candidate_surname, 
$candidate_consultant_givenname, $candidate_consultant_surname, 
$candidate_consultant_email) = mysql_fetch_row($candidate_query);

Any ideas why this might be? Is there a better way to write the statements 
that might work around it?


More information about the thelist mailing list