mysql_data_seek

(PHP3 , PHP4 )

mysql_data_seek -- Move internal result pointer

Description

int mysql_data_seek (int result_identifier, int row_number)

Returns: true on success, false on failure.

mysql_data_seek() moves the internal row pointer of the MySQL result associated with the specified result identifier to point to the specified row number. The next call to mysql_fetch_row() would return that row.

Row_number starts at 0.

Példa 1. MySQL data seek example

  1 
  2 <?php
  3     $link = mysql_pconnect ("kron", "jutta", "geheim")
  4         or die ("Could not connect");
  5 
  6     mysql_select_db ("samp_db")
  7         or die ("Could not select database");
  8 
  9     $query = "SELECT last_name, first_name FROM friends";
 10     $result = mysql_query ($query)
 11         or die ("Query failed");
 12 
 13     # fetch rows in reverse order
 14 
 15     for ($i = mysql_num_rows ($result) - 1; $i >=0; $i--) {
 16         if (!mysql_data_seek ($result, $i)) {
 17             printf ("Cannot seek to row %d\n", $i);
 18             continue;
 19         }
 20 
 21         if(!($row = mysql_fetch_object ($result)))
 22             continue;
 23 
 24         printf ("%s %s<BR>\n", $row->last_name, $row->first_name);
 25     }
 26 
 27     mysql_free_result ($result);
 28 ?>
 29