Page 1 of 1

How to refresh mysql_fetch_assoc() or reset?

Posted: Mon Sep 27, 2004 3:25 pm
by ljCharlie
I want to display the result from the MySQL database query twice on the page. The first, I have this:

Code: Select all

<?
$row_rsScholarshipDetails = mysql_fetch_assoc($rsScholarshipDetails);
	$category = $row_rsScholarshipDetails["category"];
         echo "Category: ".$category."<br>";
?>
Then further down the page I did this:

Code: Select all

<?
$totalRows = mysql_num_rows($rsScholarshipDetails);
     if($totalRows > 0){
          while ($row_rsScholarshipDetails = mysql_fetch_assoc($rsScholarshipDetails)){
               $require1 = $row_rsScholarshipDetails["reqr1"];
               //then create my table and display my results from the query into a 
              //table
              }
          }
?>
Now, the problem is that the second display of result skips the first data in the database. If delete or didn't have the firest display then everything works out fine. So how do I prevent it from skipping the firest data in the datbase?

ljCharlie

Posted: Mon Sep 27, 2004 3:30 pm
by feyd
each call to a fetch function gets the next available record in the results. So you either need to seek (hint) back to the information, or what I often do if the results are short-ish, just save off the data into an array so I can play with the results all I want without having to go back to mysql for data again and again.

Posted: Mon Sep 27, 2004 3:36 pm
by ljCharlie
Thanks! I'll give that a try.

ljCharlie