using MySQL result set multiple times ?

Discussion in 'PHP' started by domainsurfer, Feb 14, 2009.

  1. #1
    I retreive data from a mysql db and display it:

    $images = mysql_query("select * from images");
    
    while($row=mysql_fetch_array($images))
    {
               echo "Image : $row[image]";
    } 
    
    PHP:
    Now, i want to use result of same query in another part of document.
    How do i do that ?

    This doesnt work :

    while($row=mysql_fetch_array($images))
    {
               echo "Thumbnail : $row[thumb]";
    }
    PHP:
     
    domainsurfer, Feb 14, 2009 IP
  2. reptile1903

    reptile1903 Member

    Messages:
    9
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    36
    #2
    Try to it:

    
    $images2 = mysql_query("select * from images");
    
    while($row2 = mysql_fetch_array($images2))
    {
               echo "Thumbnail : $row2[thumb]";
    }
    
    PHP:
     
    reptile1903, Feb 14, 2009 IP
  3. unski84

    unski84 Peon

    Messages:
    133
    Likes Received:
    2
    Best Answers:
    0
    Trophy Points:
    0
    #3
    No need to do extra query, you just need to move the data pointer to start.

    Check mysql_data_seek
     
    unski84, Feb 14, 2009 IP