mirror of
https://github.com/sigmasternchen/php-doc-en
synced 2025-03-16 00:48:54 +00:00
added docs for mysql_fetch_assoc
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@33062 c90b9560-bf6c-de11-be94-00142212c4b1
This commit is contained in:
parent
3a06d06133
commit
519544ccbd
1 changed files with 64 additions and 3 deletions
|
@ -593,7 +593,7 @@ echo mysql_errno().": ".mysql_error()."<BR>";
|
|||
<refnamediv>
|
||||
<refname>mysql_fetch_array</refname>
|
||||
<refpurpose>
|
||||
Fetch a result row as an associative array
|
||||
Fetch a result row as an associative array, a numeric array, or both.
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
|
@ -643,15 +643,76 @@ select t1.f1 as foo t2.f1 as bar from t1, t2
|
|||
</para>
|
||||
<para>
|
||||
For further details, see also
|
||||
<function>mysql_fetch_row</function>.
|
||||
<function>mysql_fetch_row</function> and <function>mysql_fetch_assoc</function>.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>Mysql_fetch_array</function></title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
mysql_connect ($host, $user, $password);
|
||||
$result = mysql_db_query ("database","select * from table");
|
||||
$result = mysql_db_query ("database","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_free_result ($result);
|
||||
?>
|
||||
</programlisting>
|
||||
</example>
|
||||
</refsect1>
|
||||
</refentry>
|
||||
|
||||
<refentry id="function.mysql-fetch-assoc">
|
||||
<refnamediv>
|
||||
<refname>mysql_fetch_assoc</refname>
|
||||
<refpurpose>
|
||||
Fetch a result row as an associative array
|
||||
</refpurpose>
|
||||
</refnamediv>
|
||||
<refsect1>
|
||||
<title>Description</title>
|
||||
<funcsynopsis>
|
||||
<funcprototype>
|
||||
<funcdef>array <function>mysql_fetch_assoc</function></funcdef>
|
||||
<paramdef>int <parameter>result</parameter></paramdef>
|
||||
</funcprototype>
|
||||
</funcsynopsis>
|
||||
<para>
|
||||
Returns an associative array that corresponds to the fetched row,
|
||||
or false if there are no more rows.</para>
|
||||
<para>
|
||||
<function>mysql_fetch_assoc</function> is eqivilant to calling
|
||||
<function>mysql_fetch_array</function> with MYSQL_ASSOC for the
|
||||
optional second parameter. It only returns an associative array.
|
||||
This is the way <function>mysql_fetch_array</function> originally
|
||||
worked. If you need the numeric indices as well as the
|
||||
associative, use <function>mysql_fetch_array</function>.
|
||||
</para>
|
||||
<para>
|
||||
If two or more columns of the result have the same field names,
|
||||
the last column will take precedence. To access the other column(s)
|
||||
of the same name, you must use <function>mysql_fetch_array</function> and
|
||||
have it return the numeric indices as well.
|
||||
</para>
|
||||
<para>
|
||||
An important thing to note is that using
|
||||
<function>mysql_fetch_assoc</function> is NOT significantly
|
||||
slower than using <function>mysql_fetch_row</function>, while it
|
||||
provides a significant added value.
|
||||
</para>
|
||||
<para>
|
||||
For further details, see also
|
||||
<function>mysql_fetch_row</function> and <function>mysql_fetch_array</function>.
|
||||
</para>
|
||||
<example>
|
||||
<title><function>Mysql_fetch_assoc</function></title>
|
||||
<programlisting role="php">
|
||||
<?php
|
||||
mysql_connect ($host, $user, $password);
|
||||
$result = mysql_db_query ("database","select * from table");
|
||||
while ($row = mysql_fetch_assoc ($result)) {
|
||||
echo $row["user_id"];
|
||||
echo $row["fullname"];
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue