[eluser]Derek Allard[/eluser]
yeah, CI returns a multi-dimensional array, and that's not super helpful. There are 2 ways to approach this, but I'd try this one first. Set your model up as
Code:
function getGroupsBySubtypeId($id)
{
// the actual query
$this->db->where('subtype_id', $id)
$query = $this->db->get('photo_group');
// a blank array, this will hold our constructed results
$photos = array();
if ($query->num_rows() >= 1)
{
foreach ($query->result() as $photo)
{
// build the array
$photos[$photo->group_id] = $photo->name;
}
}
else
{
return FALSE; // you may want to get more clever here...
}
return $photos;
}
now in your controller, it'd look like
Code:
function somepage()
{
$this->load->model('photos_model');
$this->load->helper('form');
$id = $this->input->get_post('whatever_your_field_is_called');
$data['photos_dropdown'] = form_dropdown('photos', $this->photos_model->getGroupsBySubtypeId($id);
$this->load->view('the_view', $data);
}
You may need to adapt some of it for your specific application, but I think the general idea is here.
One thing I'm not really hitting is how to return this data using "AJAX". The reason is because there are so many things this might look like.