Jump to content

Archived

This topic is now archived and is closed to further replies.

ViperSBT

Creating an array

Recommended Posts

OK, here is the scenario. I run a SQL query that generates 32 rows of results containing id, name, image.

What I need to do with this is to create and array that contains each row of data and includes an "array key" for each row.

example SQL return:
123, fred, fred.jpg
145, wilma, wilma.jpg

I want that to be an array:
1, 123, fred, fred.jpg
2, 145, wilma, wilma.jpg

I have tried several ways and have had nothing but frustration... Once the array is built how do I access the information, say I just want to pull Wilma's row and skip Fred?

Share this post


Link to post
Share on other sites
[code]
while ($list = mysql_fetch_array($result)) {
   $blah[] = $list;
}
[/code]

edit: sorry, forgot to show how to access:

the array keys will be the names of the columns in your database. so for instance, if wilma and fred's column name is 'name':
[code]
$x = 0;
while ($blah[$x]) {
   if ($blah[$x]['name'] == 'wilma') {
       foreach($blah[$x] as $key => $val) {
           echo $key . " : " . $val . "<br>";
       }
   }
   $x++;
}
[/code]

Share this post


Link to post
Share on other sites
while ($list = mysql_fetch_array($result)) {
$blah[] = $list;
}

I believe this will give results as 0=>"blah", field=>"blah" no?

mysql_fetch_assoc () ?

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.