Re: Array question
| From: | Daniel Convissor | Date: | Thu, 13 Jul 2000 13:50:09 +0000 |
| Subject: | Re: Array question | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-6440@lists.php.net to get a copy of this message | ||
Hi Emile:
Emile Axelrad wrote:
>
> I want to insert into an array, $common["blah"], for each row in a table
> query. I want the key to be $row["settingname"] and the value to be
> $row["settingvalue"]
> .....
> while ($row = mysql_fetch_array($result)) {
> $common[$row["settingname"]] = $row["settingvalue"];
> }
First, you'll want to have the fetch array function generate only the
associative (named) and drop the enumerated (column numbered) elements of the
array, so call hte function like this: mysql_fetch_array($result,
MYSQL_ASSOC).
Now, why not just use the fetch array function to stick the row into the
$common array at the outset?
Similarly, in your while loop you can state $common = $row. If that's not
what you want for some reason, then put another while loop within your while
loop:
while ($row = mysql_fetch_array($result)) {
while(list($Key, $Val) = each($row)) {
$common[$Key] = $Val;
}
}
--Dan
--
T H E A N A L Y S I S A N D S O L U T I O N S C O M P A N Y
More than just answers. Solutions. (SM)
http://www.analysisandsolutions.com/
4015 7 Av #4, Brooklyn NY 11232 v: 718-854-0335 f: 718-854-0409