Skip to main content
More indicative title, cleaned body, added tags
Source Link
mickmackusa
  • 49.2k
  • 13
  • 98
  • 165

CodeIgniter Dropdown from How to use query result set data in CodeIgniter's form_dropdown() helper function

protected $tbl_name = 'club'; public function get($id = 0, $object = TRUE) { // select * from users where id = 0 // check if id is provided if($id) { // id provided - retrieve a specific user $query = $this->db->get_where($this->tbl_name, array('id' => $id)); // check if object type is requested if($object) { // object is requested $data = $query->row(); } else { // array is requested $data = $query->row_array(); } } else { // id not provided - retrieve all users $query = $this->db->get($this->tbl_name); // check if object type is requested if($object) { // object is requested $data = $query->result(); } else { // array is requested $data = $query->result_array(); } } return $data; } 
protected $tbl_name = 'club'; public function get($id = 0, $object = TRUE) { // select * from users where id = 0 // check if id is provided if($id) { // id provided - retrieve a specific user $query = $this->db->get_where($this->tbl_name, array('id' => $id)); // check if object type is requested if($object) { // object is requested $data = $query->row(); } else { // array is requested $data = $query->row_array(); } } else { // id not provided - retrieve all users $query = $this->db->get($this->tbl_name); // check if object type is requested if($object) { // object is requested $data = $query->result(); } else { // array is requested $data = $query->result_array(); } } return $data; } 
<tr><td><?php echo form_label('Club Name: ', 'clubname'); ?></td><td><?php echo form_dropdown('clubname', $clubname['name']); ?></td><td><?php echo form_error('clubname'); ?></td></tr> 
<tr> <td> <?php echo form_label('Club Name: ', 'clubname'); ?> </td> <td> <?php echo form_dropdown('clubname', $clubname['name']); ?> </td> <td> <?php echo form_error('clubname'); ?> </td> </tr> 

CodeIgniter Dropdown from query

protected $tbl_name = 'club'; public function get($id = 0, $object = TRUE) { // select * from users where id = 0 // check if id is provided if($id) { // id provided - retrieve a specific user $query = $this->db->get_where($this->tbl_name, array('id' => $id)); // check if object type is requested if($object) { // object is requested $data = $query->row(); } else { // array is requested $data = $query->row_array(); } } else { // id not provided - retrieve all users $query = $this->db->get($this->tbl_name); // check if object type is requested if($object) { // object is requested $data = $query->result(); } else { // array is requested $data = $query->result_array(); } } return $data; } 
<tr><td><?php echo form_label('Club Name: ', 'clubname'); ?></td><td><?php echo form_dropdown('clubname', $clubname['name']); ?></td><td><?php echo form_error('clubname'); ?></td></tr> 

How to use query result set data in CodeIgniter's form_dropdown() helper function

protected $tbl_name = 'club'; public function get($id = 0, $object = TRUE) { // select * from users where id = 0 // check if id is provided if($id) { // id provided - retrieve a specific user $query = $this->db->get_where($this->tbl_name, array('id' => $id)); // check if object type is requested if($object) { // object is requested $data = $query->row(); } else { // array is requested $data = $query->row_array(); } } else { // id not provided - retrieve all users $query = $this->db->get($this->tbl_name); // check if object type is requested if($object) { // object is requested $data = $query->result(); } else { // array is requested $data = $query->result_array(); } } return $data; } 
<tr> <td> <?php echo form_label('Club Name: ', 'clubname'); ?> </td> <td> <?php echo form_dropdown('clubname', $clubname['name']); ?> </td> <td> <?php echo form_error('clubname'); ?> </td> </tr> 
Source Link
user1269625
  • 3.2k
  • 26
  • 82
  • 114

CodeIgniter Dropdown from query

I am new in codeIgniter and I having a bit of trouble with my database and dropdown menu.

Here is my function to get the information I need...

protected $tbl_name = 'club'; public function get($id = 0, $object = TRUE) { // select * from users where id = 0 // check if id is provided if($id) { // id provided - retrieve a specific user $query = $this->db->get_where($this->tbl_name, array('id' => $id)); // check if object type is requested if($object) { // object is requested $data = $query->row(); } else { // array is requested $data = $query->row_array(); } } else { // id not provided - retrieve all users $query = $this->db->get($this->tbl_name); // check if object type is requested if($object) { // object is requested $data = $query->result(); } else { // array is requested $data = $query->result_array(); } } return $data; } 

Here is where I call it in my controller

$data['clubname'] = $this->club_model->get(); 

and this is in my view for the dropdown

<tr><td><?php echo form_label('Club Name: ', 'clubname'); ?></td><td><?php echo form_dropdown('clubname', $clubname['name']); ?></td><td><?php echo form_error('clubname'); ?></td></tr> 

but I get these errors

A PHP Error was encountered Severity: Notice Message: Undefined index: name Filename: individual/individual_club.php Line Number: 7 A PHP Error was encountered Severity: Warning Message: Invalid argument supplied for foreach() Filename: helpers/form_helper.php Line Number: 331 

What Am I doing wrong?