Name
mysql_row_seek()
Synopsis
MYSQL_ROW_OFFSET mysql_row_seek(MYSQL *result,
MYSQL_ROW_OFFSET offset)Use this function to move the pointer of a results set to
the row given as the second argument of the function. The pointer
given must use the MYSQL_ROW_OFFSET structure. Use
a function such as mysql_row_tell() to
determine the offset in the proper format. Here is an example:
...
MYSQL_ROW_OFFSET special_location;
while((row = mysql_fetch_row(result)) != NULL)
{
if(strcmp(row[1], "1000") == 0)
{
special_location = mysql_row_tell(result);
continue;
}
if(!mysql_more_results(mysql))
{
mysql_row_seek(result, special_location);
printf("%s (%s) \n", row[1], row[0]);
break;
}
printf("%s (%s) \n", row[1], row[0]);
}
...In this example, a list of clients is retrieved, but the
developer wants the row with a client identification number of 1000 to
be displayed last. So, an if statement is used to
check for the special record. When it finds the row it’s looking for,
the mysql_row_tell() function is used to make
a note of the point in the results set in which it was found. The
remainder of the while statement in which the row
is to be printed is then skipped. Using the
mysql_more_results() function, another
if statement watches for the end of the results
set. If it determines that there are no more rows in the results set
to print, it will move the pointer back to the special client using
the mysql_row_seek() function and the pointer
saved with mysql_row_tell(), print out that particular row’s ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access