RE: [PHP] Endless 'while' loops?

From: Jay Blanchard (jay.blanchard_at_niicommunications.com)
Date: 10/30/03


Date: Thu, 30 Oct 2003 06:21:36 -0600
To: "Dave G" <ml@autotelic.com>, <php-general@lists.php.net>


[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.



Relevant Pages

  • Re: Passing an array of structuresfrom a pointer?
    ... to only declare structs in headers and then define the ... the struct should be declared ... what if you have a simple array like this: ... In the header we would declare? ...
    (microsoft.public.vc.language)
  • Re: vb.net class
    ... about fixed array lenghts or using ReDim statements. ... code ensures everything in the array is a String because you declare it ... Count can be generated from the time list, not need to store ...
    (microsoft.public.dotnet.languages.vb)
  • Re: Scope of Variant / Array
    ... Even though you declared the array "public" in the main (parent) form, ... a form code module is the same as a class module. ... Constants, fixed-length strings, arrays, user-defined types and Declare ...
    (microsoft.public.access.formscoding)
  • Re: ReDim not working as expected. Array expert needed.
    ... Any dimensions you declare your variable in are wiped out, ... variable as a variant, I next told you not to redim it. ... examples of how array dimensions work in VBA. ...
    (microsoft.public.excel.programming)
  • Re: Looking to improve program
    ... You generally should declare your variables in the smallest scope ... array. ... Now that you have the hash, you can use it instead of four nearly ... There's also no real reason to be assigning ...
    (comp.lang.perl.misc)