• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How do i convert a query result into an associative array?

I need to pass an associative array to form_dropdown(), but I don't know how to convert.

I've tried this in my model.

$query  = $this->db->query("SELECT id, category FROM categories WHERE id = '$id'");

foreach($query->result() as $row)
   $category_array[] = $row;

foreach($query->result() as $row)
  $category_array[] = array(
    'id'       => $row->id,
    'cateogry' =>$row->$category

For the latter,the code yeilds this:
The bold numbers are the soft indexing apparently and the numbers above the words are the values of the options. Naturally I only want the words to show up in the menu.

Here is what I have in my Controller
$queries['category_array'] = $this->categorymodel->getcategories();

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2021 MyBB Group.