While Loop Problem.

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • adriann
    New Member
    • Aug 2006
    • 25

    #1

    While Loop Problem.

    I have a strange problem whereby an attempt at a looped SQL query only passes successfully once.
    I get the error..
    Warning: mysql_fetch_arr ay(): supplied argument is not a valid MySQL result resource in...
    ... at the line where the WHILE loop is placed.

    It is the mysql_fetch_arr ay command embedded in the while loop that seems to be the problem,.
    Therefore, my question is... Is my "WHILE" in Example 1, statement legal Syntax?

    ---------------------------------------------
    EXAMPLE 1: Only the first pass works. Looping gives error.
    ---------------------------------------------
    $SQL1 = 'SELECT * FROM tickets WHERE status = "closed" ';
    $result = mysql_query($SQ L1) or die('Query failed:'.mysql_ error());
    while ($row = mysql_fetch_arr ay($result, MYSQL_ASSOC)) {
    Do_lots_of_stuf f();
    } //End While Loop.
    Report_on_Stuff ();
    exit;

    ---------------------------------------------
    EXAMPLE 2: This works
    ---------------------------------------------
    $SQL1 = 'SELECT * FROM tickets WHERE status = "closed" ';
    $result = mysql_query($SQ L1) or die('Query failed:'.mysql_ error());
    $row = mysql_fetch_arr ay($result, MYSQL_ASSOC);
    Do_lots_of_stuf f();
    ---------------------------------------------
    Report_on_Stuff ();
    exit;
Working...