PHP Manual
Prev |  | Next

# mysql_data_seek

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.

Example 1. MySQL data seek example

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

Prev | Home | Next
mysql_create_db | Up | mysql_db_query