我已经在这个CodeIgniter查询上工作了几个小时了,但我找不出问题所在。这是SQL表,其中包含数据和每个字段的名称。表名为bodystyle。
make |模型| bodystyle
福特| F-150猛禽4X4乘员驾驶室|前部驾驶室
宝马||
宝马|| 35i |
宝马| X5 | 35i
宝马| X5 | 45i
宝马| X5 | 35i
下面是我使用CodeIgniter运行的查询
$make =$this->input->post('make');
$model =$this->input->post('model');
$this->db->select('bodystyle');
$this->db->from('bodystyle');
$this->db->where('make', $make);
$this->db->where('model', $model);
$records = $this->db->get('');
$output = null;
foreach ($records->result() as $row){
$output .= $row->bodystyle . ', ';
}
echo $output;
$make = Ford
$model = Raptor 4X4 Crew Cab我得到的输出是FRONT CAB, ,35i, 45i, 35i
你能看出来为什么它在拉动所有的体型吗?
我想要它只是从品牌和型号上拉出来
发布于 2013-06-18 11:13:42
我发现select子句中的列名和表名是相同的。确保提供了正确的列名和表名。以下是编辑后的查询,请检查。
您的结果查询应该是
$records->result('array')而不是
$records->result()尝试:
$make =$this->input->post('make');
$model =$this->input->post('model');
$this->db->select(column_name);
$this->db->from(table_name);
$this->db->where(array(
'make' => $make,
'model' => $model
));
$records = $this->db->get();
$result = $records->result('array');
print_r($result);https://stackoverflow.com/questions/17159930
复制相似问题