php-doc-en/reference/mysql/functions/mysql-fetch-assoc.xml
Hartmut Holzgraefe 5b9fc29465 revision tags added
git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@78496 c90b9560-bf6c-de11-be94-00142212c4b1
2002-04-17 06:45:35 +00:00

89 lines
2.9 KiB
XML

<?xml version="1.0" encoding="iso-8859-1"?>
<!-- $Revision: 1.2 $ -->
<!-- splitted from ./en/functions/mysql.xml, last change in rev 1.45 -->
<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>
<methodsynopsis>
<type>array</type><methodname>mysql_fetch_assoc</methodname>
<methodparam><type>resource</type><parameter>result</parameter></methodparam>
</methodsynopsis>
<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 equivalent 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 either need to access the
result with numeric indices by using
<function>mysql_fetch_row</function> or add alias names.
See the example at the <function>mysql_fetch_array</function>
description about aliases.
</para>
<para>
An important thing to note is that using
<function>mysql_fetch_assoc</function> is <emphasis>not
significantly</emphasis> 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">
<![CDATA[
<?php
mysql_connect($host, $user, $password);
mysql_select_db($database);
$query = "select * from table";
$result = mysql_query($query);
while ($row = mysql_fetch_assoc($result)) {
echo $row["user_id"];
echo $row["fullname"];
}
mysql_free_result($result);
?>
]]>
</programlisting>
</example>
</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
-->