mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
inserted additional samples
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@79309 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
66252c0eff
commit
1d60d615a4
1 changed files with 52 additions and 19 deletions
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0" encoding="iso-8859-1"?>
|
||||
<!-- $Revision: 1.2 $ -->
|
||||
<!-- $Revision: 1.3 $ -->
|
||||
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.27 -->
|
||||
<refentry id="function.mysql-fetch-array">
|
||||
<refnamediv>
|
||||
|
@ -33,13 +33,14 @@
|
|||
make an alias for the column. For aliased columns, you cannot
|
||||
access the contents with the original column name (by using
|
||||
<literal>'field'</literal> in this example).
|
||||
<informalexample>
|
||||
<example>
|
||||
<title>Query with duplicate field names</title>
|
||||
<programlisting role="sql">
|
||||
<![CDATA[
|
||||
select tone.field as foo ttwo.field as bar from tone, ttwo
|
||||
select table1.field as foo table2.field as bar from table1, table2
|
||||
]]>
|
||||
</programlisting>
|
||||
</informalexample>
|
||||
</example>
|
||||
</para>
|
||||
<para>
|
||||
An important thing to note is that using
|
||||
|
@ -62,30 +63,62 @@ select tone.field as foo ttwo.field as bar from tone, ttwo
|
|||
using MYSQL_NUM, you only get number indices (as
|
||||
<function>mysql_fetch_row</function> works).
|
||||
</para>
|
||||
<para>
|
||||
For further details, see also
|
||||
<function>mysql_fetch_row</function> and
|
||||
<function>mysql_fetch_assoc</function>.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>mysql_fetch_array</function> example</title>
|
||||
<title>mysql_fetch_array with MYSQL_NUM</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect($host, $user, $password);
|
||||
mysql_select_db("database");
|
||||
$result = mysql_query("select user_id, fullname from table");
|
||||
while ($row = mysql_fetch_array($result)) {
|
||||
echo "user_id: ".$row["user_id"]."<br />\n";
|
||||
echo "user_id: ".$row[0]."<br />\n";
|
||||
echo "fullname: ".$row["fullname"]."<br />\n";
|
||||
echo "fullname: ".$row[1]."<br />\n";
|
||||
}
|
||||
mysql_connect("localhost", "mysql_user", "mysql_password");
|
||||
|
||||
$result = mysql_query("SELECT id, name FROM mytable");
|
||||
|
||||
while (($row = mysql_fetch_array($result, MYSQL_NUM))
|
||||
printf ("ID: %s Name: %s", $row[0], $row[1]);
|
||||
|
||||
mysql_free_result($result);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<example>
|
||||
<title>mysql_fetch_array with MYSQL_ASSOC</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect("localhost", "mysql_user", "mysql_password");
|
||||
|
||||
$result = mysql_query("SELECT id, name FROM mytable");
|
||||
|
||||
while (($row = mysql_fetch_array($result, MYSQL_ASSOC))
|
||||
printf ("ID: %s Name: %s", $row["id"], $row["name"]);
|
||||
|
||||
mysql_free_result($result);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<example>
|
||||
<title>mysql_fetch_array with MYSQL_BOTH</title>
|
||||
<programlisting role="php">
|
||||
<![CDATA[
|
||||
<?php
|
||||
mysql_connect("localhost", "mysql_user", "mysql_password");
|
||||
|
||||
$result = mysql_query("SELECT id, name FROM mytable");
|
||||
|
||||
while (($row = mysql_fetch_array($result, MYSQL_BOTH))
|
||||
printf ("ID: %s Name: %s", $row[0], $row["name"]);
|
||||
|
||||
mysql_free_result($result);
|
||||
?>
|
||||
]]>
|
||||
</programlisting>
|
||||
</example>
|
||||
<para>
|
||||
For further details, see also
|
||||
<function>mysql_fetch_row</function> and
|
||||
<function>mysql_fetch_assoc</function>.
|
||||
</para>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
|
|
Loading…
Reference in a new issue