Try this

$exclude_query = "SELECT hostname FROM exclusion";
$exclude_results = mysql_query($exclude_query, $Prod);

while ($exclude = mysql_fetch_array($exclude_results)) {
  echo $exclude["hostname"]."\n";
}

-Wendell



-----Original Message-----
From: NIPP, SCOTT V (SBCSI) [mailto:[EMAIL PROTECTED] 
Sent: Thursday, April 07, 2005 12:15 PM
To: php-db@lists.php.net
Subject: [PHP-DB] Problem with foreach looping...

        I am attempting to use a simple foreach loop on a query result,
and I am only getting the first element of the array back.  Here is the
code...

$exclude_query = "SELECT hostname FROM exclusion";
$exclude_results = mysql_query($exclude_query, $Prod);
$exclude = mysql_fetch_array($exclude_results, MYSQL_NUM);

foreach ($exclude as $row) {
  echo "$row\n";
}

        I don't understand how I am just getting a single item back from
this.  The query actually returns all 13 entries in the exclusion table.
I have tested the query via the mysql client.  I also get all 13
elements back if I loop via the following.

while ($test = mysql_fetch_array($results, MYSQL_NUM)) {
  echo "$test[0]\n";
}

        Is my PHP somehow broke, or am I just missing something here?
Thanks.

Scott Nipp
Phone:  (214) 858-1289
E-mail:  [EMAIL PROTECTED]
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

Reply via email to