How to refresh mysql_fetch_assoc() or reset?

Questions about the MySQL, PostgreSQL, and most other databases, as well as using it with PHP can be asked here.

Moderator: General Moderators

Post Reply
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

How to refresh mysql_fetch_assoc() or reset?

Post 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
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post 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.
ljCharlie
Forum Contributor
Posts: 289
Joined: Wed May 19, 2004 8:23 am

Post by ljCharlie »

Thanks! I'll give that a try.

ljCharlie
Post Reply