Welcome Guest, Not a member yet? Register   Sign In
Using foreach in codeigniter view to generate select options
#4

[eluser]thefatladysingsopera[/eluser]
I now have this model


Code:
public function das_groups_list($current_id){
$query = $this->db->query("select group_title,group_name from all_groups");
foreach ($query->result() as $row)
{
   $data[] = array(
               'group_title' => $row->group_title,
               'group_name' => $row->group_name
          );
}
    return $data;
}

and this is the controller

Code:
public function edit_event($id = 0,$current_id=0){
    $id = $this->uri->segment(3);
$current_id = $this->ion_auth->get_user_id();
    $data['event'] = $this->asgard->das_event_edit($id);
$data['groups'] = $this->asgard->das_groups_list($current_id);
$this->load->view('editevent',$data);
}

I get this array

Code:
Array
(
    [0] => Array
        (
            [group_title] => le_glutten borg
            [group_name] => legluttenborg
        )

    [1] => Array
        (
            [group_title] => le grand gandalf
            [group_name] => legrandgandalf
        )

    [2] => Array
        (
            [group_title] => rhyyuj
            [group_name] => rhyyuj
        )

)

when i
Code:
print_r ($groups)
in my view however
Code:
$groups['group_title']
complains of an illegal offset.

Update:

This
Code:
echo $groups[0]['group_title'];
gets me only the first group.How should i list all groups?.

I have this

Code:
<select class="form-control"><option value="">&lt;?php for($i = 0; $i > count($groups); $i++){echo $groups[$i]['group_title'];} ?&gt;</option></select>

which does not display any value.


Messages In This Thread
Using foreach in codeigniter view to generate select options - by El Forum - 09-05-2014, 08:22 AM



Theme © iAndrew 2016 - Forum software by © MyBB