Name

mysql_data_seek

Synopsis

boolean mysql_data_seek (qresource query, int row)

Moves the internal pointer related to a query to a specific row, where zero refers to the first row in a result set. After calling this function, the next row that is retrieved through mysql_fetch_array( ), mysql_fetch_assoc( ), mysql_fetch_object( ), or mysql_fetch_row( ) will be the row specified.

The function returns true on success and false on failure. A common source of failure is that there are no rows in the result set associated with the query resource handle. A prior call to mysql_num_rows( ) can be used to determine if results were returned from the query.

Example

<?php
  $query = "SELECT * FROM presents";
  
  $connection = mysql_connect("localhost", "fred", "shhh");
  mysql_select_db("wedding", $connection);
  
  $result = mysql_query($query, $connection);
  
  if (!mysql_data_seek($result, 7))
     echo "Could not seek to the eighth row!"; 
  
  $row = mysql_fetch_array($result); 
  
  echo "Eighth row: " . $row["present"];       
?>

Get Managing & Using MySQL, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.