Hello大家我的程序有问题我需要在我的数据库中检查多个号码,但是当我测试它时只显示一个结果我的代码:
/*in mt View*/
$data = array(
'name' => 'search_id',
'id' => 'search_id',
'placeholder' => 'numbers_test',
'autofocus' =>"autofocus",
'rows' => '20'
);
echo form_textarea($data,set_value('search_id'));
/* in my model */
$this->db->select('*');
$this->db->from('personal_info');
$this->db->where_in('p_id', $this->input->post('search_id'));
return $this->db->get();
我在等你的帮助解决这个问题
答案 0 :(得分:2)
如果您从1,5,4,8
获取逗号分隔ID(如字符串$this->input->post('search_id')
等),则更新您的代码
/* in my model */
$this->db->select('*');
$this->db->from('personal_info');
// Explode string into array to make where_in clause work
$this->db->where_in('p_id', explode(',', $this->input->post('search_id')));
return $this->db->get();
如official docs建议你需要在IN
子句
答案 1 :(得分:0)
您必须返回查询的结果。进行更改,
/* In my model */
$this->db->select('*');
$this->db->from('personal_info');
$this->db->where_in('p_id', $this->input->post('search_id'));
$query = $this->db->get();
return $query->result_array(); // You've to return the result of the query
另外,正如@Saqueib在评论中所说,如果有疑问,请尝试一些调试,
echo $this->db->last_query(); exit;
或强>
echo '<pre>'; print_r($query->result_array()); exit;