mysql_data_seek()
bool mysql_data_seek(connection,row)
Use this function in conjunction with the
mysql_fetch_row() function to change the
current row being fetched to the one specified in the second argument.
The connection identifier is given as the first argument. The function
returns true if it’s successful; false if it’s unsuccessful. Here is
an example:
...
$sql_stmnt = "SELECT wrid, clientid, description
FROM workreq";
$results = mysql_query($sql_stmnt);
$count = mysql_num_rows($results);
if ($count > 6) mysql_data_seek($results, $count - 6);
$row = mysql_fetch_row($results);
while($row = mysql_fetch_object($results)) {
print "WR-" . $row->wrid . " Client-" . $row->clientid .
" - " . $row->description . "\n";
}
...In this script excerpt, the SQL statement is selecting the work
request identification numbers for all rows in the table. The results
set is stored in $results. Using the
mysql_num_rows() function, the number of rows
is determined and placed in the $count variable. To
be able to display only the last five work requests, the script calls
mysql_data_seek(). The results set is given
as the first argument. In order to get the first row of a results set,
the offset would be set to 0—so if a results set contains only one
row, the row count of 1 minus 1 would need to be given as the second
argument of mysql_data_seek(). For the
example here, to get the last five records of the results set, the
number of rows is reduced by six to move the pointer to the row before
the fifth-to-last row. Here is the last line of the output of this
script:
WR-5755 Client-1000 - Can't connect to network.