thecableguy2011 Posted February 25, 2011 Share Posted February 25, 2011 Hi I am trying to store the results of a mysql query into a php array. Here is the code i am using $test = implode(",",$_GET['checkbox']); $query = mysql_query("SELECT categoryTitle FROM `category` where categoryid in ($test)"); $test2 = array(); while ($result = mysql_fetch_assoc($query)) { $test2[] = $result; } $test3 = implode(", ",$test2); print_r($test3); Everything works fine until implode the array. When i try to print after the implode the result is "Array, Array". if i remove the implode it prints "Array ( [0] => Array ( [categoryTitle] => Escalators & Lifts ) [1] => Array ( [categoryTitle] => Human Resource/Payroll/ Training ) )" The values here are ture. Im thinking that its storing an array inside another array so cannot implode. Is there something i can do to solve this Link to comment https://forums.phpfreaks.com/topic/228778-php-array-from-query/ Share on other sites More sharing options...
codefossa Posted February 25, 2011 Share Posted February 25, 2011 That's because $result is an array. You need to do it like this. $test2[] = $result['column']; Link to comment https://forums.phpfreaks.com/topic/228778-php-array-from-query/#findComment-1179463 Share on other sites More sharing options...
Muddy_Funster Posted February 25, 2011 Share Posted February 25, 2011 wouldn't it be easier to just replace while ($result = mysql_fetch_assoc($query)){ $test2[] = $result; } with $test2 = mysql_fetch_assoc($query); ?? Link to comment https://forums.phpfreaks.com/topic/228778-php-array-from-query/#findComment-1179467 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.