简体   繁体   English

如何在codeigniter中使用“ where in”方法?

[英]How to use “where in” method in codeigniter?

Hello Everybody i have problem with my program i need check multi number in my database but when i test it just show only one result my code : 大家好,我的程序有问题,我需要检查数据库中的多号,但是当我测试它时,我的代码只显示一个结果:

/*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();

i waiting your help for this problem 我等待你的帮助来解决这个问题

If you are getting input as comma separated ids like in string 1,5,4,8 etc from $this->input->post('search_id') then update your code like this 如果您从$this->input->post('search_id')获取以逗号分隔的ID(例如字符串1,5,4,8等)的输入, 1,5,4,8像这样更新代码

/* 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();

as official docs suggest you need to provide array of options in IN clause 官方文档所示,您需要在IN子句中提供选项数组

You have to return the result of the query. 您必须返回查询结果 Make changes, 做出改变,

/* 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


Also as @Saqueib said in comments, try some debugging when in doubt, 就像@Saqueib在评论中说的那样,如有疑问,请尝试进行一些调试

echo $this->db->last_query(); exit;

OR 要么

echo '<pre>'; print_r($query->result_array()); exit;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM