Reputation: 2425
In my database i have a field called ARG_1. i contains Home,Work,Work2
Now i fetch this from database.
And I want to show this three as separate checkbox. Like this:
input type='checkbox' name='checkboxvar[]' value='Option One'>Home<br>
<input type='checkbox' name='checkboxvar[]' value='Option Two'>Work<br>
<input type='checkbox' name='checkboxvar[]' value='Option Three'>Work2
How to do this?
I did this but didnt work:
$params = $this->model->get();
foreach($params as $value) $new_val = explode(',',$value->arg_1);
{
echo form_checkbox($new_val);
}
Upvotes: 1
Views: 1219
Reputation: 442
On your model
Write this query
public function yourMethodName(){
$this->db->select('ARG_1');
$q=$this->db->get('your-table-name');
return $q->result();
}
and on controller first load your model and then call model method which have you made and send data to your view page
like this...
$this->load->model('your-model-name'); # Load model
$data['details']=$this->your-model-name->yourMethodName(); # Load Model Method
$this->load->view('your-view-page-name',$data); #Load your view page
and finally on View page
foreach($details as $rows){
$exp_arr=explode(',',$rows->ARG_1); # convert ARG_1 string value into array
for($i=0;$i<count($exp_arr);$i++){
echo "<input type='checkbox' name='checkboxvar[]' value='Option Two'>".$exp_arr[$i]."<br>";
}
}
Hope this code will help you
Upvotes: 2
Reputation: 957
Try this One of the simple way
$sno=1;
$i=0;
for($sno;$sno<=$params->num_rows();$sno++)
{
echo '<input type="checkbox" name="checkboxvar[]" id="checkboxvar" value="<?php echo $params[$i]->check_box_value; ?>">';
$i++;
}
Upvotes: 0