Reset a result source in PHP with mysql_data_seek

  1. $result = mysql_query("SELECT names FROM table;");          
  2.  
  3. while($row=mysql_fetch_array($result,MYSQL_ASSOC)) {
  4.  
  5.           //procedure
  6. }
  7.  
  8. mysql_data_seek($result,0); // Reuse your recordset
  9.  
  10. while($row=mysql_fetch_array($result,MYSQL_ASSOC)) {
  11.  
  12.         //procedure
  13.  
  14. }

5 Responses to “Reset a result source in PHP with mysql_data_seek”

  1. cherly Says:

    Thanks for the special work and information!

  2. Wahoo Says:

    Thank you for sharing!

  3. Erik Says:

    looks to me that $row would be the same everytime.
    what’s the point of the first ‘while’ then? why not just use a join?

    please, what am i missing? thanks

  4. admin Says:

    Erik, good catch! thanks!

  5. Matt Says:

    Thank you! That saved me about 10 db queries in a script!

Leave a Reply

watch free movies online download movies online free movies online