note 26723 added to function.mysql-fetch-array

From: Date: Sun, 10 Nov 2002 22:27:45 +0000
Subject: note 26723 added to function.mysql-fetch-array
Groups: php.notes 
Request: Send a blank email to php-notes+get-39272@lists.php.net to get a copy of this message
I did find 'jb at stormvision's' code useful above, but instead of the number of rows you need the number of fields; otherwise you get an error. So, it should read like the following: $result=mysql_query("select * from mydata order by 'id'")or die('died'); $num_fields = mysql_num_fields($result); $j=0; $x=1; while($row=mysql_fetch_array($result)){ for($j=0;$j<$num_fields;$j++){ $name = mysql_field_name($result, $j); $object[$x][$name]=$row[$name]; }$x++; } For Later in the script you may use the below array to gain access to your data $i=1; $ii=count($object); //quick access function for($i=1;$i<=$ii;$i++){ echo $object[$i]['your_field_name']; } I have tested this in my apps and it works great! :-) -- http://www.php.net/manual/en/function.mysql-fetch-array.php http://master.php.net/manage/user-notes.php?action=edit+26723 http://master.php.net/manage/user-notes.php?action=delete+26723 http://master.php.net/manage/user-notes.php?action=reject+26723

« previous php.notes (#39272) next »