php-doc-en/reference/mysqli/functions/mysqli-data-seek.xml
Georg Richter ba25e8d0b8 - added more samples
- marked undocumented functions for embedded server and
  replication as experimental


git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@151917 c90b9560-bf6c-de11-be94-00142212c4b1
2004-02-20 13:05:10 +00:00

145 lines
4.5 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.11 $ -->
<refentry id="function.mysqli-data-seek">
<refnamediv>
<refname>mysqli_data_seek</refname>
<refname>result->data_seek</refname>
<refpurpose>Adjusts the result pointer to an arbitary row in the result</refpurpose>
</refnamediv>
<refsect1>
<title>Description</title>
<para>Procedural style:</para>
<methodsynopsis>
<type>bool</type><methodname>mysqli_data_seek</methodname>
<methodparam><type>object</type><parameter>result</parameter></methodparam>
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
</methodsynopsis>
<para>Object oriented style (method):</para>
<classsynopsis>
<ooclass><classname>result</classname></ooclass>
<methodsynopsis>
<type>bool</type>
<methodname>data_seek</methodname>
<methodparam><type>int</type><parameter>offset</parameter></methodparam>
</methodsynopsis>
</classsynopsis>
<para>
The <function>mysqli_data_seek</function> function seeks to an arbitrary result pointer
specified by the <parameter>offset</parameter> in the result set represented by
<parameter>result</parameter>. The <parameter>offset</parameter> parameter must be between
zero and the total number of rows minus one (0..<function>mysqli_num_rows</function> - 1).
</para>
<note>
<para>
This function can only be used with unbuffered results attained from the use of the
<function>mysqli_store_result</function> or <function>mysqli_query</function> functions.
</para>
</note>
</refsect1>
<refsect1>
<title>Return values</title>
<para>
&return.success;
</para>
</refsect1>
<refsect1>
<title>See also</title>
<para>
<function>mysqli_store_result</function>,
<function>mysqli_fetch_row</function>,
<function>mysqli_num_rows</function>.
</para>
</refsect1>
<refsect1>
<title>Example</title>
<para>
<example>
<title>Object oriented style</title>
<programlisting role="php">
<![CDATA[
<?php
/* Open a connection */
$mysqli = new mysqli("localhost", "my_user", "my_password", "test");
$mysqli->query( "DROP TABLE IF EXISTS friends");
$mysqli->query( "CREATE TABLE friends (id int, name varchar(30))");
$mysqli->query( "INSERT INTO friends VALUES (1, 'Greant'),
(2, 'Stocker'), (3, 'Rethans'), (4, 'Wendel')");
/* Get some rows */
$query = "SELECT name FROM friends ORDER BY name";
$result = $mysqli->query( $query) or die(mysqli_error($link));
$total = $result->field_count;
if ($total > 0) { // there is at least one row
/* Get the last employee */
$result->data_seek($result->num_rows -1);
$friend = $result->fetch_row();
printf ("Friends name : %s\n", $friend[0]);
}
$result->close();
$mysqli->close();
?>
]]>
</programlisting>
</example>
<example>
<title>Object oriented style</title>
<programlisting role="php">
<![CDATA[
<?php
/* Open a connection */
$link = mysqli_connect("localhost", "my_user", "my_password", "test");
mysqli_query($link, "DROP TABLE IF EXISTS friends");
mysqli_query($link, "CREATE TABLE friends (id int, name varchar(30))");
mysqli_query($link, "INSERT INTO friends VALUES (1, 'Greant'),
(2, 'Stocker'), (3, 'Rethans'), (4, 'Wendel')");
/* Get some rows */
$query = "SELECT name FROM friends ORDER BY name";
$result = mysqli_query($link, $query) or die(mysqli_error($link));
$total = mysqli_num_fields($result);
if ($total > 0) { /* there is at least one row */
/* Get the last employee */
mysqli_data_seek($result, mysqli_num_rows($result) -1);
$friend = mysqli_fetch_row($result);
printf ("Friends name : %s\n", $friend[0]);
}
mysqli_free_result($result);
mysqli_close($link);
?>
]]>
</programlisting>
</example>
</para>
</refsect1>
</refentry>
<!-- Keep this comment at the end of the file
Local variables:
mode: sgml
sgml-omittag:t
sgml-shorttag:t
sgml-minimize-attributes:nil
sgml-always-quote-attributes:t
sgml-indent-step:1
sgml-indent-data:t
indent-tabs-mode:nil
sgml-parent-document:nil
sgml-default-dtd-file:"../../../../manual.ced"
sgml-exposed-tags:nil
sgml-local-catalogs:nil
sgml-local-ecat-files:nil
End:
vim600: syn=xml fen fdm=syntax fdl=2 si
vim: et tw=78 syn=sgml
vi: ts=1 sw=1
-->