Moving to a specific row in MySQL result set
Posted: Wed Oct 22, 2003 3:28 pm
I have a page which first displays all rows of a MySQL result set (which leaves me at the end of the set). I then want to go to a specific row in the set based on a value in the field (I can't use a row offset because I don't know which row has that value).
I could just do another query with a WHERE statement, but it seems like I shouldn't have to since I've already got the entire set.
Now I want to go to the row where the field $event_id == $number (a session variable) so that the results of that row can be displayed in a form for editing. Any help with code to do this without running the query again?
Thanks, Ruth
I could just do another query with a WHERE statement, but it seems like I shouldn't have to since I've already got the entire set.
Code: Select all
$event_query = "SELECT * FROM event";
$event_result = mysql_query($event_query)
or die ("Couldn't execute event query");
//display all rows
while ($event_row = mysql_fetch_array($event_result,MYSQL_ASSOC)) {
extract ($event_row);
echo "\$event_id: $event_id<br>
\$event_name: $event_name<br>";
}
//go back to first record in result set.
$new_event_row = mysql_data_seek($event_result,0);Thanks, Ruth