Re: Mysql & Array Question
| From: | Rasmus Lerdorf | Date: | Sat, 20 Jan 2001 21:33:32 +0000 |
| Subject: | Re: Mysql & Array Question | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-35845@lists.php.net to get a copy of this message | ||
while($row = mysql_fetch_array($id,MYSQL_ASSOC)) {
foreach($row as $index=>$value) {
$z[$index][] = $value;
}
}
For a table with 3 rows and fields abc and def in each row this would
produce an array like this:
$z[abc][0]
$z[def][0]
$z[abc][1]
$z[def][1]
$z[abc][2]
$z[def][2]
-Rasmus
On Sat, 20 Jan 2001, Jeff Lacy wrote:
> Hello Everyone,
>
> I am trying to make a page that will interact with mysql. I need to be
> able to access the result of my mysql_query by using a for loop. I made a
> little function that will sortof do this, but it returns a numeric array.
> Of course, I want an associative array (becauses things get screwy with a
> null). Does anyone know how to make something like what I want? Thanks a
> bunch :-)
>
> This is my current function:
>
> function returnArray ($id) {
> $z = array (array());
> for ($i = 0; $row = mysql_fetch_array ($id); $i++) {
> for ($a = 0; $a < sizeof ($row); $a++) {
> $z[$i][$a] = $row[$a];
> }
> }
> return $z;
> }
>
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, e-mail: php-general-unsubscribe@lists.php.net
> For additional commands, e-mail: php-general-help@lists.php.net
> To contact the list administrators, e-mail: php-list-admin@lists.php.net
>