Skip to Content
MySQL in a Nutshell, 2nd Edition
book

MySQL in a Nutshell, 2nd Edition

by Russell J. T. Dyer
April 2008
Intermediate to advanced
566 pages
21h 55m
English
O'Reilly Media, Inc.
Content preview from MySQL in a Nutshell, 2nd Edition

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

More than 5,000 organizations count on O’Reilly

AirBnbBlueOriginElectronic ArtsHomeDepotNasdaqRakutenTata Consultancy Services

QuotationMarkO’Reilly covers everything we've got, with content to help us build a world-class technology community, upgrade the capabilities and competencies of our teams, and improve overall team performance as well as their engagement.
Julian F.
Head of Cybersecurity
QuotationMarkI wanted to learn C and C++, but it didn't click for me until I picked up an O'Reilly book. When I went on the O’Reilly platform, I was astonished to find all the books there, plus live events and sandboxes so you could play around with the technology.
Addison B.
Field Engineer
QuotationMarkI’ve been on the O’Reilly platform for more than eight years. I use a couple of learning platforms, but I'm on O'Reilly more than anybody else. When you're there, you start learning. I'm never disappointed.
Amir M.
Data Platform Tech Lead
QuotationMarkI'm always learning. So when I got on to O'Reilly, I was like a kid in a candy store. There are playlists. There are answers. There's on-demand training. It's worth its weight in gold, in terms of what it allows me to do.
Mark W.
Embedded Software Engineer

You might also like

MySQL in a Nutshell

MySQL in a Nutshell

Russell J. T. Dyer
MySQL Cookbook

MySQL Cookbook

Paul DuBois
MySQL 8 Cookbook

MySQL 8 Cookbook

Karthik Appigatla

Publisher Resources

ISBN: 9780596514334Errata Page