ViperSBT Posted June 14, 2006 Share Posted June 14, 2006 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.jpg145, wilma, wilma.jpgI want that to be an array:1, 123, fred, fred.jpg2, 145, wilma, wilma.jpgI 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? Quote Link to comment https://forums.phpfreaks.com/topic/11949-creating-an-array/ Share on other sites More sharing options...
.josh Posted June 14, 2006 Share Posted June 14, 2006 [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] Quote Link to comment https://forums.phpfreaks.com/topic/11949-creating-an-array/#findComment-45372 Share on other sites More sharing options...
joquius Posted June 14, 2006 Share Posted June 14, 2006 while ($list = mysql_fetch_array($result)) { $blah[] = $list;}I believe this will give results as 0=>"blah", field=>"blah" no?mysql_fetch_assoc () ? Quote Link to comment https://forums.phpfreaks.com/topic/11949-creating-an-array/#findComment-45406 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.