[thelist] php/mysql - two consecutive select statements

Dave Preston caffiend at simianbrotherhood.org
Fri Nov 16 09:15:50 CST 2001

Wow, that's pretty scary.. I'd *strongly* urge you to ditch using list
and use mysql_fetch_obj instead of mysql_fetch_row. The main reason
being that if you ever change your schema, you'll be screwed if you
forget to update any of your php scripts.

On Fri, Nov 16, 2001 at 03:44:09AM -0500, noah wrote:
> 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);

$obj = mysql_fetch_object($job_query, MYSQL_ASSOC);
$client_id = $obj->client_id;

> $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) = 
> mysql_fetch_row($client_query);
$obj = mysql_fetch_obj($client_query, MYSQL_ASSOC);
$client_name = $obj->client_name;
$client_consultant_givename = $obj->client_consultant_givename;
... etc ...

this is all pre-coffee so your results may vary from the database in my


More information about the thelist mailing list