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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.