我想从mysql表中选择列,我选择了名称作为输入值 . 在我看来,必须选择列名作为多个输入字段 . 在此选择选项中,值等于数据库中“pass_due”表中的列名 .
<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>
这是我的控制器中的功能
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);
}
}
在我这样的模型中 .
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();
}
}
当我运行此代码时,它选择表中的所有列,而不仅仅是选定的列 . 并且它还显示错误为为foreach()提供的无效参数 .
3 回答
您可以使用此新模型方法从db中检索数据 . 将此方法插入模型中
那么这将回归你的期望 . 还建议您使用通用模型,除了为每个表使用单独的模型 .
在您的模型中返回查询,如下所示
在您的控制器中获取数据
在您的视图页面中