note 42043 added to function.mysql-fetch-array

From: Date: Fri, 30 Apr 2004 14:37:30 +0000
Subject: note 42043 added to function.mysql-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-69041@lists.php.net to get a copy of this message
This is a variation for the function mysql_fetch_array_r. (Original posted by brendan [at] unsharpmask [dot] com on 24-Nov-2003 09:38 (function mysql_fetch_array_r($result, $index_row = "", $fetch = MYSQL_ASSOC). I wrote this one because I did not want to hold the "$index_row" argument any way. // $result : the result of a sql query // $result_type: the same that mysql_fetch_array function mysql_fetch_array_r($result,$result_type=MYSQL_ASSOC) { $arr=array(); for($i=0;$i<@mysql_num_rows($result);$i++) { // faster ? array_push($arr,@mysql_fetch_array($result,$result_type)); // faster ? } return $arr; // on error, $arr is empty } /* // Uncomment test data for this function $server="localhost"; $user="root"; $password=""; $database="mysql_db"; $sql="SELECT * FROM mysql_table1;"; $link=mysql_connect($server,$user,$password); mysql_select_db($database); $result=mysql_query($sql); $arr=mysql_fetch_array_r($result,MYSQL_ASSOC); if (!empty($arr)) { echo sizeof($arr)."<br />"; print_r($arr); } mysql_free_result($result); mysql_close($link); // */ (This version does not handle errors, sorry). ---- Manual Page -- http://www.php.net/manual/en/function.mysql-fetch-array.php Edit -- http://master.php.net/manage/user-notes.php?action=edit+42043 Delete -- http://master.php.net/manage/user-notes.php?action=delete+42043&report=yes Reject -- http://master.php.net/manage/user-notes.php?action=reject+42043&report=yes Search -- http://master.php.net/manage/user-notes.php

« previous php.notes (#69041) next »