RE: [PHP] Endless 'while' loops?
| From: | Jay Blanchard | Date: | Thu, 30 Oct 2003 12:21:36 +0000 |
| Subject: | RE: [PHP] Endless 'while' loops? | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-168139@lists.php.net to get a copy of this message | ||
[snip]
But in the rest of the script I can't find where they declare and fill
this array.
[/snip]
The subscriber array is filled by the query. Since PHP is not a strongly
typed language there is no need to declare the array.
$sql = "SELECT
foo, bar FROM customers WHERE
status = 'active'";
/*run the query, testing as we go*/
if(!($result = mysql_query($sql, $connection_string))){
echo "MySQL reports an error " . mysql_error() . "\n";
exit();
}
/*if the query worked the $result 'holds' the info*/
while ( $subscriber = mysql_fetch_row($result)){
echo $subscriber[0]."\t"; should have info from foo column
echo $subscriber[1]."\n"; should have info from bar column
}
When mysql_fetch_row($result) returns FALSE the while loop exits.