OK. Maybe I am going about this in the wrong manner. Here is the SQL statement that I am starting out with. $query = "SELECT Hostname FROM Data WHERE CPU_IN_SVC = \"Y\" AND CPU_DNS = \"blah.com\" ORDER BY Hostname ASC"; This query provides me a complete list of all the systems in our organization. The following query provides me with a list of systems in an exclusion table that should not be displayed. $exclude_query = "SELECT hostname FROM exclusion"; This one is obviously quite simple and straight-forward. The next query is one that will generate a list of systems on which the user already has an account. $query2= "SELECT Data.Hostname FROM Data, acct_db WHERE Data.CPU_IN_SVC = \"Y\" AND Data.CPU_DNS = \"blah.com\" AND acct_db.key1 LIKE '$var%' AND acct_db.key1 LIKE CONCAT(\"%\", Data.Hostname) ORDER BY Hostname ASC"; This query is very much like the first, but it also looks into the acct_db table to match userids and hostnames. This is currently a separate query because this data is used to display information in a separate section of the web page. $query3= "SELECT Data.Hostname FROM Data, accounts WHERE Data.CPU_IN_SVC = \"Y\" AND Data.CPU_DNS = \"sbcld.sbc.com\" AND accounts.uid = '$var' AND accounts.system = Data.Hostname AND accounts.ctime IS NULL ORDER BY Hostname ASC"; This query is also similar to the first , but it looks into the accounts table to determine if the user has already submitted an account request for the server, AND that this account has not yet been created (ctime IS NULL). Like the query above, this is a separate query since it is used to populate a different section of the web page. I do not know if it is possible to somehow combine all 4 of these queries into a single complex query. This would be preferred in my mind as it would let the server do more work in fewer queries. What I would like to do is have a single query that would return the hostnames with some kind of key that could then be used to determine what criteria the query matched to specifically. I am guessing that this would be a numeric value that would be a secondary array element associated with the hostname. I would then write my display code to check the value of this element to determine how/where to display the data. Thanks in advance for any help in this. I have no idea if this is possible, but I am guessing that it is. Scott Nipp Phone: (214) 858-1289 E-mail: sn4265@xxxxxxx Web: http:\\ldsa.sbcld.sbc.com -----Original Message----- From: Bastien Koert [mailto:bastien_k@xxxxxxxxxxx] Sent: Monday, March 28, 2005 11:13 AM To: NIPP, SCOTT V (SBCSI); php-db@xxxxxxxxxxxxx Subject: RE: RE: Further MySQL query problems... why wouldn't you just run a query to return only the elements that you want? Bastien >From: "NIPP, SCOTT V (SBCSI)" <sn4265@xxxxxxx> >To: <php-db@xxxxxxxxxxxxx> >Subject: RE: Further MySQL query problems... >Date: Mon, 28 Mar 2005 10:49:24 -0600 > > Oops... Correction to the last line of the script. > <?php } while ($blah = mysql_fetch_array($exclude_results)); ?> > > Should be... > <?php } while ($blah = array_shift($temp)); ?> >Scott Nipp >Phone: (214) 858-1289 >E-mail: sn4265@xxxxxxx >Web: http:\\ldsa.sbcld.sbc.com > > > > -----Original Message----- > > From: NIPP, SCOTT V (SBCSI) > > Sent: Monday, March 28, 2005 10:47 AM > > To: 'php-db@xxxxxxxxxxxxx' > > Subject: Further MySQL query problems... > > > > I am having trouble in the following code. Basically, I want to > > query two separate database tables and then generate an array from > > these two queries. The first query will return a list of ALL systems. > > The second query will return a list of systems that should be > > excluded. The problem is that this is getting me nowhere. Here is > > the pertinent code... > > > > $query = "SELECT CPU_Hostname FROM AllMid_Data > > WHERE CPU_IN_SVC = \"Y\" > > AND CPU_DNS = \"sbcld.sbc.com\" > > ORDER BY CPU_Hostname ASC"; > > $results = mysql_query($query, $Prod) or die(mysql_error()); > > $system = mysql_fetch_array($results, MYSQL_NUM); > > $exclude_query = "SELECT hostname FROM exclusion"; > > $exclude_results = mysql_query($exclude_query, $Prod); > > $exclude = mysql_fetch_array($exclude_results, MYSQL_NUM); > > $temp = array_diff($system, $exclude); > > <?php do { > > $sys = $blah[0]; > > echo "<tr>"; ?> > > <?php echo $sys; ?> > > <?php echo "</tr>"; } ?> > > <?php } while ($blah = mysql_fetch_array($exclude_results)); ?> > > > > I have cut out a lot of extraneous stuff that I don't think is > > pertinent. Please let me know if you see something causing my > > problems. The first query table has about 900 entries and the query > > returns about 90 hostnames. The exclude table query has only 13 > > hostnames and obviously returns all. I am looking for a way to > > display the approximately 77 entries that are NOT in the exclude > > table. Thanks again. > > > > Scott Nipp > > Phone: (214) 858-1289 > > E-mail: sn4265@xxxxxxx > > Web: http:\\ldsa.sbcld.sbc.com > > > > > >-- >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