<HTML ><HEAD ><TITLE >mysql_data_seek</TITLE ><META NAME="GENERATOR" CONTENT="Modular DocBook HTML Stylesheet Version 1.44"><LINK REL="HOME" TITLE="PHP Manual" HREF="manual.html"><LINK REL="UP" TITLE="MySQL functions" HREF="ref.mysql.html"><LINK REL="PREVIOUS" TITLE="mysql_create_db" HREF="function.mysql-create-db.html"><LINK REL="NEXT" TITLE="mysql_db_query" HREF="function.mysql-db-query.html"></HEAD ><BODY BGCOLOR="#FFFFFF" TEXT="#000000" LINK="#0000FF" VLINK="#840084" ALINK="#0000FF" ><DIV CLASS="NAVHEADER" ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TH COLSPAN="3" ALIGN="center" >PHP Manual</TH ></TR ><TR ><TD WIDTH="10%" ALIGN="left" VALIGN="bottom" ><A HREF="function.mysql-create-db.html" >Prev</A ></TD ><TD WIDTH="80%" ALIGN="center" VALIGN="bottom" ></TD ><TD WIDTH="10%" ALIGN="right" VALIGN="bottom" ><A HREF="function.mysql-db-query.html" >Next</A ></TD ></TR ></TABLE ><HR ALIGN="LEFT" WIDTH="100%"></DIV ><H1 ><A NAME="function.mysql-data-seek" >mysql_data_seek</A ></H1 ><DIV CLASS="refnamediv" ><A NAME="AEN18537" ></A >mysql_data_seek -- Move internal result pointer</DIV ><DIV CLASS="refsect1" ><A NAME="AEN18540" ></A ><H2 >Description</H2 ><DIV CLASS="funcsynopsis" ><P ></P ><CODE CLASS="FUNCDEF" >int mysql_data_seek</CODE >(int result_identifier, int row_number);<P ></P ></DIV ><P > Returns: true on success, false on failure. </P ><P > <B CLASS="function" >mysql_data_seek()</B > moves the internal row pointer of the MySQL result associated with the specified result identifier to point to the specified row number. The next call to <A HREF="function.mysql-fetch-row.html" ><B CLASS="function" >mysql_fetch_row()</B ></A > would return that row. </P ><P > <TT CLASS="parameter" ><I >Row_number</I ></TT > starts at 0. </P ><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" CLASS="EXAMPLE" ><TR ><TD ><DIV CLASS="example" ><P ><B >Example 1. MySQL data seek example</B ></P ><TABLE BORDER="0" BGCOLOR="#E0E0E0" WIDTH="100%" ><TR ><TD ><PRE CLASS="programlisting" > 1 2 <?php 3 $link = mysql_pconnect ("kron", "jutta", "geheim") { 4 or die ("Could not connect"); 5 } 6 7 mysql_select_db ("samp_db") { 8 or die ("Could not select database"); 9 } 10 11 $query = "SELECT last_name, first_name FROM friends"; 12 $result = mysql_query ($query) { 13 or die ("Query failed"); 14 } 15 16 # fetch rows in reverse order 17 18 for ($i = mysql_num_rows ($result) - 1; $i >=0; $i--) { 19 if (!mysql_data_seek ($result, $i)) { 20 printf ("Cannot seek to row %d\n", $i); 21 continue; 22 } 23 24 if(!($row = mysql_fetch_object ($result))) 25 continue; 26 27 printf ("%s %s<BR>\n", $row->last_name, $row->first_name); 28 } 29 30 mysql_free_result ($result); 31 ?> 32 </PRE ></TD ></TR ></TABLE ></DIV ></TD ></TR ></TABLE ></DIV ><DIV CLASS="NAVFOOTER" ><HR ALIGN="LEFT" WIDTH="100%"><TABLE WIDTH="100%" BORDER="0" CELLPADDING="0" CELLSPACING="0" ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" ><A HREF="function.mysql-create-db.html" >Prev</A ></TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="manual.html" >Home</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" ><A HREF="function.mysql-db-query.html" >Next</A ></TD ></TR ><TR ><TD WIDTH="33%" ALIGN="left" VALIGN="top" >mysql_create_db</TD ><TD WIDTH="34%" ALIGN="center" VALIGN="top" ><A HREF="ref.mysql.html" >Up</A ></TD ><TD WIDTH="33%" ALIGN="right" VALIGN="top" >mysql_db_query</TD ></TR ></TABLE ></DIV ></BODY ></HTML >