RE: [PHP-DB] MySQL - Query within a query

2005-03-19 Thread Bastien Koert
Unlike ASP, $result1 is a handle to the dataset, not the data set itself. 
You need to access the data first and then incorporate that into your query 
like this:

$l = 2;
$result1 = (SELECT * FROM Drivers WHERE League = $l);
$row = mysql_fetch_array($result1);
$driverID = $row['DriverID'];
$result2 = mysql_query(SELECT DriverID, Driver, CarNbr FROM Drivers LEFT
JOIN $LeagueList ON Drivers.DriverID = $driverID
   WHERE $driverID) Is Null ORDER BY Drivers.DriverID);
hth
Bastien


From: Pete Ruby [EMAIL PROTECTED]
Reply-To: Pete Ruby [EMAIL PROTECTED]
To: php-db@lists.php.net
Subject: [PHP-DB] MySQL - Query within a query
Date: Wed, 16 Mar 2005 00:03:19 -0500
I am looking to do the following w/ MySQL and PHP.  Have 1 query that gets
results, then use those results in another query:
$l = 2;
$result1 = (SELECT * FROM Drivers WHERE League = $l);
$result2 = mysql_query(SELECT DriverID, Driver, CarNbr FROM Drivers LEFT
JOIN $LeagueList ON Drivers.DriverID = $Result1.DriverID
   WHERE $Result1.DriverID) Is Null ORDER BY Drivers.DriverID);
I can do it w/ Access and MSSQL, but if I try in MySQL, i get an error, 
both
in DBManager (MySQL interface), and in PHP.

Any help is appreciated.  Thanx!
Pete
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


Re: [PHP-DB] MySQL - Query within a query

2005-03-19 Thread Larry E . Ullman
I am looking to do the following w/ MySQL and PHP.  Have 1 query that 
gets
results, then use those results in another query:

$l = 2;
$result1 = (SELECT * FROM Drivers WHERE League = $l);
$result2 = mysql_query(SELECT DriverID, Driver, CarNbr FROM Drivers 
LEFT
JOIN $LeagueList ON Drivers.DriverID = $Result1.DriverID
   WHERE $Result1.DriverID) Is Null ORDER BY Drivers.DriverID);
If you're using MySQL 4.1, which supports subqueries, you might be able 
to write this all up as one nice query (using a sub-select).

Larry
--
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[PHP-DB] MySQL - Query within a query

2005-03-18 Thread Pete Ruby
I am looking to do the following w/ MySQL and PHP.  Have 1 query that gets 
results, then use those results in another query:

$l = 2;
$result1 = (SELECT * FROM Drivers WHERE League = $l);

$result2 = mysql_query(SELECT DriverID, Driver, CarNbr FROM Drivers LEFT 
JOIN $LeagueList ON Drivers.DriverID = $Result1.DriverID
   WHERE $Result1.DriverID) Is Null ORDER BY Drivers.DriverID);

I can do it w/ Access and MSSQL, but if I try in MySQL, i get an error, both 
in DBManager (MySQL interface), and in PHP.

Any help is appreciated.  Thanx!

Pete 

-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php