2002-04-15 00:12:54 +00:00
|
|
|
<?xml version="1.0" encoding="iso-8859-1"?>
|
2007-06-16 21:08:14 +00:00
|
|
|
<!-- $Revision: 1.20 $ -->
|
2005-03-30 04:07:29 +00:00
|
|
|
<refentry id="function.mysql-data-seek">
|
|
|
|
<refnamediv>
|
|
|
|
<refname>mysql_data_seek</refname>
|
|
|
|
<refpurpose>Move internal result pointer</refpurpose>
|
|
|
|
</refnamediv>
|
2007-01-28 05:22:02 +00:00
|
|
|
|
2005-03-30 08:14:56 +00:00
|
|
|
<refsect1 role="description">
|
|
|
|
&reftitle.description;
|
2005-03-30 05:05:08 +00:00
|
|
|
<methodsynopsis>
|
|
|
|
<type>bool</type><methodname>mysql_data_seek</methodname>
|
2005-03-31 07:47:25 +00:00
|
|
|
<methodparam><type>resource</type><parameter>result</parameter></methodparam>
|
2005-03-30 05:05:08 +00:00
|
|
|
<methodparam><type>int</type><parameter>row_number</parameter></methodparam>
|
|
|
|
</methodsynopsis>
|
2005-03-30 04:07:29 +00:00
|
|
|
<para>
|
|
|
|
<function>mysql_data_seek</function> 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
|
2006-04-26 16:20:04 +00:00
|
|
|
to a MySQL fetch function, such as <function>mysql_fetch_assoc</function>,
|
|
|
|
would return that row.
|
2005-03-30 04:07:29 +00:00
|
|
|
</para>
|
|
|
|
<para>
|
|
|
|
<parameter>row_number</parameter> starts at 0. The
|
|
|
|
<parameter>row_number</parameter> should be a value in the range from 0 to
|
|
|
|
<function>mysql_num_rows</function> - 1. However if the result set
|
|
|
|
is empty (<function>mysql_num_rows</function> == 0), a seek to 0 will
|
2007-06-16 21:08:14 +00:00
|
|
|
fail with a <link linkend="errorfunc.constants.errorlevels.e-warning">E_WARNING</link> and
|
2005-03-30 04:07:29 +00:00
|
|
|
<function>mysql_data_seek</function> will return &false;.
|
|
|
|
</para>
|
2005-03-30 05:05:08 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="parameters">
|
|
|
|
&reftitle.parameters;
|
|
|
|
<para>
|
|
|
|
<variablelist>
|
2005-03-31 07:47:25 +00:00
|
|
|
&mysql.result.description;
|
2005-03-30 05:05:08 +00:00
|
|
|
<varlistentry>
|
|
|
|
<term><parameter>row_number</parameter></term>
|
|
|
|
<listitem>
|
|
|
|
<para>
|
|
|
|
The desired row number of the new result pointer.
|
|
|
|
</para>
|
|
|
|
</listitem>
|
|
|
|
</varlistentry>
|
|
|
|
</variablelist>
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="returnvalues">
|
|
|
|
&reftitle.returnvalues;
|
|
|
|
<para>
|
|
|
|
&return.success;
|
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="examples">
|
|
|
|
&reftitle.examples;
|
2005-03-30 04:07:29 +00:00
|
|
|
<para>
|
|
|
|
<example>
|
|
|
|
<title><function>mysql_data_seek</function> example</title>
|
|
|
|
<programlisting role="php">
|
2002-04-15 00:12:54 +00:00
|
|
|
<![CDATA[
|
|
|
|
<?php
|
2004-02-20 17:36:42 +00:00
|
|
|
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
|
|
|
|
if (!$link) {
|
|
|
|
die('Could not connect: ' . mysql_error());
|
|
|
|
}
|
|
|
|
$db_selected = mysql_select_db('sample_db');
|
|
|
|
if (!$db_selected) {
|
|
|
|
die('Could not select database: ' . mysql_error());
|
|
|
|
}
|
|
|
|
$query = 'SELECT last_name, first_name FROM friends';
|
|
|
|
$result = mysql_query($query);
|
|
|
|
if (!$result) {
|
|
|
|
die('Query failed: ' . mysql_error());
|
|
|
|
}
|
2004-01-05 13:03:26 +00:00
|
|
|
/* fetch rows in reverse order */
|
|
|
|
for ($i = mysql_num_rows($result) - 1; $i >= 0; $i--) {
|
|
|
|
if (!mysql_data_seek($result, $i)) {
|
|
|
|
echo "Cannot seek to row $i: " . mysql_error() . "\n";
|
|
|
|
continue;
|
|
|
|
}
|
2002-04-15 00:12:54 +00:00
|
|
|
|
2004-02-20 17:36:42 +00:00
|
|
|
if (!($row = mysql_fetch_assoc($result))) {
|
2004-01-05 13:03:26 +00:00
|
|
|
continue;
|
2004-02-20 17:36:42 +00:00
|
|
|
}
|
2002-04-15 00:12:54 +00:00
|
|
|
|
2004-02-20 17:36:42 +00:00
|
|
|
echo $row['last_name'] . ' ' . $row['first_name'] . "<br />\n";
|
2004-01-05 13:03:26 +00:00
|
|
|
}
|
2002-04-15 00:12:54 +00:00
|
|
|
|
2004-01-05 13:03:26 +00:00
|
|
|
mysql_free_result($result);
|
2002-04-15 00:12:54 +00:00
|
|
|
?>
|
|
|
|
]]>
|
2005-03-30 04:07:29 +00:00
|
|
|
</programlisting>
|
|
|
|
</example>
|
|
|
|
</para>
|
2005-03-30 05:05:08 +00:00
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="notes">
|
|
|
|
&reftitle.notes;
|
|
|
|
<note>
|
|
|
|
<para>
|
|
|
|
The function <function>mysql_data_seek</function> can be used in
|
|
|
|
conjunction only with <function>mysql_query</function>, not with
|
|
|
|
<function>mysql_unbuffered_query</function>.
|
|
|
|
</para>
|
|
|
|
</note>
|
|
|
|
</refsect1>
|
|
|
|
|
|
|
|
<refsect1 role="seealso">
|
|
|
|
&reftitle.seealso;
|
2005-03-30 04:07:29 +00:00
|
|
|
<para>
|
2005-03-30 05:05:08 +00:00
|
|
|
<simplelist>
|
|
|
|
<member><function>mysql_query</function></member>
|
|
|
|
<member><function>mysql_num_rows</function></member>
|
|
|
|
<member><function>mysql_fetch_row</function></member>
|
|
|
|
<member><function>mysql_fetch_assoc</function></member>
|
|
|
|
<member><function>mysql_fetch_array</function></member>
|
|
|
|
<member><function>mysql_fetch_object</function></member>
|
|
|
|
</simplelist>
|
2005-03-30 04:07:29 +00:00
|
|
|
</para>
|
|
|
|
</refsect1>
|
|
|
|
</refentry>
|
2002-04-15 00:12:54 +00:00
|
|
|
|
|
|
|
<!-- 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
|
|
|
|
-->
|