Re: Multidimensional arrays
| From: | John Kaspar | Date: | Fri, 18 Jul 2003 19:29:20 +0000 |
| Subject: | Re: Multidimensional arrays | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-155827@lists.php.net to get a copy of this message | ||
$sql = "select id, name from customer";
$rs = mysql_query($sql) or die("sql=$sql => ".mysql_error());
while ($row = mysql_fetch_assoc($rs)) {
$custarray[] = $row;
}
/*
$row is an array with the elements 'id' and 'name'
$custarray becomes a multi-array indexed starting a 0
e.g.
$custarray[0]['id'] = 5126
$custarray[0]['name'] = 'jo'
$custarray[1]['id'] = 5127
$custarray[1]['name'] = 'mark'
*/
On 7/18/2003 8:33 AM, Gary Broughton wrote:
Hi
Can anybody help me grasp multidimensional arrays please? Basically, I am
retrieving all records from one table (two fields), and want to return them
in an array.
I am converting code from ASP to PHP, and in the former I did something like
this:
select id, name from customer
redim custarray(recordcount,2)
i = 0
while not eof
custarray(i,0) = id;
custarray(i,1) = name;
i = i+1;
movenext
wend
... but all my efforts to store them in the same kind of way in PHP have
proved fruitless. Any advice would be much appreciated.
Many thanks
Gary