Jump to content

Creating an array


ViperSBT

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?
Link to comment
https://forums.phpfreaks.com/topic/11949-creating-an-array/
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]
Link to comment
https://forums.phpfreaks.com/topic/11949-creating-an-array/#findComment-45372
Share on other sites

Archived

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

×
×
  • Create New...

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.