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 Quote 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']; Quote 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); ?? Quote Link to comment https://forums.phpfreaks.com/topic/228778-php-array-from-query/#findComment-1179467 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.