CodeIgniter function for returning special dropdown -
i want create function in model bit different , need bit of help.
i have database table names, description, ids etc etc .... there 1 of each name, want return 3 entries every 1 name, prefixed number on it.
so, example, if have 2 entries in database names 'joe' , 'bob' .... want dropdown box following
<select> <option value="joe1">joe1 - description</value> <option value="joe2">joe2 - description</value> <option value="joe3">joe3 - description</value> <option value="bob1">bob1 - description</value> <option value="bob2">bob2 - description</value> <option value="bob3">bob3 - description</value>
and on additional entries in db.
i understand how normal dropdown box, not 1 this.
any grand :)
try this:
function get_users() { $this->db->select("id,name,desc"); $this->db->from("table_name"); $q = $this->db->get(); $rows = $q->row_array(); }
in controller method:
$data = array(); $data['users'] = $this->model_name->get_users(); $this->load->view('view_name',$data);
in view:
<?php echo "<select>"; foreach($users $user) { ($i=1; $i<=3; $i++) { $id = $user['id'].$i; echo '<option value="'.$id.'">'.$id.' - '.$user['desc'].'</option>'; } } echo "</select>"; ?>
Comments
Post a Comment