I want to select columns form mysql table which I have selected names as input value. In my view, have to select column names as multiple input fields. In this selection option values are equals to column names in my “pass_due” table in database.
<form id="" name=" Passdue " action="<?=base_url('index.php/Passdue_ctrl/select')?>" method="post">
<div >
<input class="date-picker" id="report_date" name="report_date" value="" placeholder="Select Date"/>
<select multiple="" class="chzn-select" id=" " data-placeholder="Select sections " name="table_feilds">
<option value="" />
<option value="below_1" /> Below month
<option value="month_1_3" /> Month 1-3
<option value="month_3_6" /> Month 3-6
<option value="month_6_9" /> Month 6-9
<option value="over_9" /> Over 9 month
</select>
</div>
<div>
<button type="submit" class="btn btn-mini btn-info">Submit</button>
<button type="reset" id="reset" class="btn btn-mini btn-info">Reset</button>
</div>
</form>
This is function in my controller
Function select (){
$fld_name =$this->input->post('table_feilds');
$reportdate=$this->input->post('report_date');
$report=$this->Passdue_model->get_report_part($fld_name,$reportdate);
If($report){
$this->data['report_part']=$report;
$this->data['fld_name']=$fld_name;
$this->load->view('Passdue_other_view',$this->data);
}
}
In my model like this.
function get_report_part1($fld_name,$reportdate)
{
$this->db->select($fld_name);
$this->db->from(‘pass_due’);
$this->db->where('fld_actORinact_date <=',$reportdate);
$query = $this->db->get();
if($query){
return $query->result();
}
}
When I run this code it select all columns from table, not only selected ones. And also it shows error as Invalid argument supplied for foreach() .
</div>