...

View Full Version : Resolved Returning values from a while loop into an array?



stfc_boy
08-08-2011, 10:34 AM
Hello,

I'm after a bit of help if possible with regards to a while loop.

I have a query, which I return the results of in a while loop and I hold each value in an array.



While($row = mysql_fetch_array($result)) {
$search_tags = array();
$search_tags = $row['name'];
}


Now what I want to do is take each of these twelve values returned and pass them to another array outside of the while loop. In this array certain numeric values already exist . I've tried this using list, but I get a message saying Variable passed to each() is not an array or object .



While($row = mysql_fetch_array($result)) {
$search_tags = array();
$search_tags = $row['name'];
}
list ($val1, $val2, $val3, $val4, $val5, $val6, $val7, $val8, $val9, $val10, $val11, $val12) = each($search_tags);
$tags = array($val1 => 42, $val2 => 38, $val3 => 32, $val4 => 29, $val5 => 26, $val6 => 24, $val7 => 20, $val8 => 16, $val9 => 12, $val10 => 11, $val11 => 10, $val12 => 8);


Can anyone please help?

Thanks

tangoforce
08-08-2011, 01:29 PM
While($row = mysql_fetch_array($result)) {
$search_tags[] = $row['name'];
}


I think thats what you're looking for with the first bit of code.. second bit I'm lost on but I've only just woken up and the head is still a bit fizzy..



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum