Professional Web Applications Themes

multiple mysql_fetch_array() calls - PHP Development

Hi All, I've got a simple query hopefully somebody can clear up for me. I need to make a query on a database to select a set of table rows, using something like: $result = mysql_query($query); I can then use mysql_fetch_array in a while loop to access each row in the result. This all works fine. However, what I'd like to do is to go through this result more than once. ie. use mysql_fetch_array() to go through each row in $result more than once. How do I do this?. There appears to be no my of resetting mysql_fetch_array back to ...

Sponsored Links
  1. #1

    Default multiple mysql_fetch_array() calls

    Hi All,
    I've got a simple query hopefully somebody can clear up for me. I need to
    make a query on a database to select a set of table rows, using something
    like:

    $result = mysql_query($query);

    I can then use mysql_fetch_array in a while loop to access each row in the
    result. This all works fine.

    However, what I'd like to do is to go through this result more than once.
    ie. use mysql_fetch_array() to go through each row in $result more than
    once. How do I do this?. There appears to be no my of resetting
    mysql_fetch_array back to the beginning of the $result once all rows have
    been erad once.

    I don't want to make multiple identical queries on the database, simply to
    read the same information.

    Any ideas?.

    Ta,
    Dave


    Sponsored Links
    Dave Guest

  2. #2

    Default Re: multiple mysql_fetch_array() calls

    Dave Moore wrote: 
    Store your first time result in your own query.. and then just loop your
    own query as many times as needed...

    $yourArray = array();
    while($row = mysql_fetch_array($result, MYSQL_ASSOC) {
    $yourArray[] = $row;
    }

    then just do this as many times as needed...

    foreach($yourArray as $rowNum => $row) {
    //$row would be same as the original $row inside the while loop
    inside this loop.
    }
    Paul Guest

  3. #3

    Default Re: multiple mysql_fetch_array() calls

    You can also use this:

    mysql_data_seek ($result, 0);


    http://us4.php.net/manual/en/function.mysql-data-seek.php

    Steve Guest

Similar Threads

  1. Multiple function calls on "creationComplete"??
    By WestSide in forum Macromedia Flex General Discussion
    Replies: 3
    Last Post: June 19th, 08:05 PM
  2. Locking on multiple asynchronous calls
    By lmcp in forum Macromedia Flex General Discussion
    Replies: 1
    Last Post: February 28th, 06:04 PM
  3. multiple calls to getURL("javascript:<functionN>")
    By stellaruser webforumsuser@macromedia.com in forum Macromedia Flash Actionscript
    Replies: 2
    Last Post: January 30th, 11:06 PM
  4. Replies: 2
    Last Post: July 18th, 03:17 AM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139