note 25348 added to function.mysql-fetch-array
| From: | jb at stormvision dot com dot na | Date: | Fri, 20 Sep 2002 12:05:15 +0000 |
| Subject: | note 25348 added to function.mysql-fetch-array | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-37029@lists.php.net to get a copy of this message | ||
This might be usefull for people that work with lots of rows and want to place them all into one
array for later usage. This script just takes care of all the tedious work one would have and puts
all neccessary field names into your array automatically. This way you can use this script over and
over for all kind of mysql functions.
$result=mysql_query("select * from mydata order by 'id'")or
die('died');
$num_rows = mysql_num_rows($result);
$j=0;
$x=1;
while($row=mysql_fetch_array($result)){
for($j=0;$j<$num_rows;$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'];
}
hope it helps
--
http://www.php.net/manual/en/function.mysql-fetch-array.php
http://master.php.net/manage/user-notes.php?action=edit+25348
http://master.php.net/manage/user-notes.php?action=delete+25348
http://master.php.net/manage/user-notes.php?action=reject+25348