mysql - issue getting the value from database to combobox -
this controller:
<?php class combobox extends ci_controller { function dynamic_combobox() { $this->load->model('combobox_model'); $data['college'] = $this->combobox_model->getcollege(); $this->load->view('header', $data); $this->load->view('left_menu', $data); $this->load->view('manage_user', $data); $this->load->view('footer', $data); } } ?>
this model:
$this->db->get('colleges'); $data = array(); if ($query->num_rows() > 0) { foreach ($query->result_array() $row){ $data[] = $row; } } $query->free_result(); return $data;
this view:
<form action="<?php echo site_url(''); ?>" method="post"> college <select name="id" id="id" style="width: 350px;"> <option class="droplist">please select colleges</option> <? if (count($college)>0) { foreach ($college $row) { echo "<option value='". $row['college_id'] . "'>" . $row['college_name'] . "</option>"; } } ?> </select> courses <select> <!--<option>ug</option> <option>pg</option>--> </select> <input class="button" type="button" value="refresh"/> </form>
try if works or not, model:
$rs = $this->db->get('colleges'); $data = array(); if ($query->num_rows() > 0) { $data = $rs->result_array(); } $query->free_result(); return $data;
your view:
if (count($college)>0){ foreach ($college $row){ echo "<option value='". $row['college_id'] . "'>" . $row['college_name'] . "</option>"; } }
edit 1:
$arr[] = array('college_id' => '1', 'college_name' => 'nadar saraswathi college of engineering , technology', 'status' => '1', 'created_by' => '1', 'modified_by' => '1', 'created_date' => '2012-09-30 22:51:25', 'modified_date' => '2012-09-30 22:50:28' ); print_r($arr); echo "<select>"; foreach ($arr $row){ echo "<option value='". $row['college_id'] . "'>" . $row['college_name'] . "</option>"; } echo "</select>";
Comments
Post a Comment