From 519544ccbd0b5cbb163e36006e332732485b0399 Mon Sep 17 00:00:00 2001 From: Brian Moon Date: Thu, 28 Sep 2000 19:27:37 +0000 Subject: [PATCH] added docs for mysql_fetch_assoc git-svn-id: https://svn.php.net/repository/phpdoc/en/trunk@33062 c90b9560-bf6c-de11-be94-00142212c4b1 --- functions/mysql.xml | 67 +++++++++++++++++++++++++++++++++++++++++++-- 1 file changed, 64 insertions(+), 3 deletions(-) diff --git a/functions/mysql.xml b/functions/mysql.xml index 4325ef3498..053ab8d15c 100644 --- a/functions/mysql.xml +++ b/functions/mysql.xml @@ -593,7 +593,7 @@ echo mysql_errno().": ".mysql_error()."<BR>"; mysql_fetch_array - Fetch a result row as an associative array + Fetch a result row as an associative array, a numeric array, or both. @@ -643,15 +643,76 @@ select t1.f1 as foo t2.f1 as bar from t1, t2 For further details, see also - mysql_fetch_row. + mysql_fetch_row and mysql_fetch_assoc. <function>Mysql_fetch_array</function> <?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"]."
\n"; + echo "user_id: ".$row[0]."
\n"; + echo "fullname: ".$row["fullname"]."
\n"; + echo "fullname: ".$row[1]."
\n"; +} +mysql_free_result ($result); +?> +
+
+
+ + + + + mysql_fetch_assoc + + Fetch a result row as an associative array + + + + Description + + + array mysql_fetch_assoc + int result + + + + Returns an associative array that corresponds to the fetched row, + or false if there are no more rows. + + mysql_fetch_assoc is eqivilant to calling + mysql_fetch_array with MYSQL_ASSOC for the + optional second parameter. It only returns an associative array. + This is the way mysql_fetch_array originally + worked. If you need the numeric indices as well as the + associative, use mysql_fetch_array. + + + 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 mysql_fetch_array and + have it return the numeric indices as well. + + + An important thing to note is that using + mysql_fetch_assoc is NOT significantly + slower than using mysql_fetch_row, while it + provides a significant added value. + + + For further details, see also + mysql_fetch_row and mysql_fetch_array. + + + <function>Mysql_fetch_assoc</function> + +<?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"]; }