Name

mysql_data_seek( )

Synopsis

void mysql_data_seek(MYSQL_RES *result, my_ulonglong offset)

Use this in conjunction with mysql_store_result( ) and a fetch function such as mysql_fetch_row( ) to change the current row being fetched to the one specified in the second argument of this function.

...
mysql_query(mysql, "SELECT client_id, client_name
                     FROM clients ORDER BY start_date");
result = mysql_store_result(mysql);
num_rows = mysql_num_rows(result);
mysql_data_seek(result, (num_rows - 8));
while((row = mysql_fetch_row(result)) != NULL)
  { printf("%s (%s) \n", row[1], row[0]); }
...

This program excerpt retrieves a list of client names along with their respective IDs. Using the mysql_data_seek( ) function in conjunction with mysql_fetch_row( ) and a while statement, the last eight clients who started with the company will be displayed.

Get MySQL in a Nutshell 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.