PHP / MySQL how many times can I use a Mysql result resource?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • gregerly
    Recognized Expert New Member
    • Sep 2006
    • 192

    PHP / MySQL how many times can I use a Mysql result resource?

    I've got a query that I run at the top of my page.

    I then want to loop thru the results (which works the first time I do it), twice. On the second time I loop thru the same result, it does not work.

    Ex:
    [PHP]//data abstraction layer which returns the result - no problems here
    $msResults=$bra in->sqlExe('select ','alliances_tb l','*','','','x allianceorder ASC');

    //loop thru results - this works great
    while(list($id, $alliance,$alli anceURL)=@mysql _fetch_row($msR esults)){
    //do something
    }[/PHP]

    then, down the page a while

    [PHP]//loop thru results a second time - this does not work
    while(list($id, $alliance,$alli anceURL)=@mysql _fetch_row($msR esults)){
    //do something
    }[/PHP]

    Can you only use a mysql result resource once? do I have to query again if I want access to the same data?

    Thanks,

    Greg
  • pbmods
    Recognized Expert Expert
    • Apr 2007
    • 5821

    #2
    Heya, Greg.

    You can in theory use a MySQL result as many times as you want...

    But you might find this to be more useful:
    [code=php]
    $alliances = array();
    while( $_row = mysql_fetch_ass oc($msResults) )
    {
    $alliances[] = $_row;
    }
    [/code]

    Then you can reference $alliances for whatever row you need.

    Comment

    • gregerly
      Recognized Expert New Member
      • Sep 2006
      • 192

      #3
      Originally posted by pbmods
      Heya, Greg.

      You can in theory use a MySQL result as many times as you want...

      But you might find this to be more useful:
      [code=php]
      $alliances = array();
      while( $_row = mysql_fetch_ass oc($msResults) )
      {
      $alliances[] = $_row;
      }
      [/code]

      Then you can reference $alliances for whatever row you need.
      That's a great solution pbmods. Thanks!

      Greg

      Comment

      • pbmods
        Recognized Expert Expert
        • Apr 2007
        • 5821

        #4
        Heya, Greg.

        You may also find this article useful.

        Comment

        Working...