Php 在不在codeigniter中工作的情况下
这是我编写select查询的函数Php 在不在codeigniter中工作的情况下,php,codeigniter,Php,Codeigniter,这是我编写select查询的函数 function userList($name,$logged_id,$friendlist) { $this->db->select("concat((mu.first_name),(' '),(mu.last_name)) AS full_name,mu.user_id,user_type",FALSE); $this->db->from("mst_users as mu"); $this-&
function userList($name,$logged_id,$friendlist)
{
$this->db->select("concat((mu.first_name),(' '),(mu.last_name)) AS full_name,mu.user_id,user_type",FALSE);
$this->db->from("mst_users as mu");
$this->db->where("user_status", "1");
$this->db->where_in("user_id",$friendlist);
$this->db->where('user_id !=', $logged_id,false);
$this->db->where("email_verified", "1");
$this->db->where("mu.first_name LIKE '%$name%'");
$this->db->or_where("mu.last_name LIKE '%$name%'");
//$this->db->limit("3");
$query = $this->db->get();
return $query->result_array();
}
这是来自控制器的函数调用
function userList(){
$arr_friend=array(127, 139, 138);
$user_list = $this->search_model->userList(a,137,$arr_friend);
}
这是查询的输出。输出错误
full_name user_id user_type
Grace 1 2
admina 126 3
hancy 127 1
vaibhavaaa 132 1
arjun 137 1
ashish 138 3
sofia 139 1
emma 140 3
vaibhav 147 3
ashish 148 1
我只想要127139138这些身份证的记录
full_name user_id user_type
hancy 127 1
ashish 138 3
sofia 139 1
输出应该是这样的这是因为您使用where\u或以错误的方式,请替换此:
$this->db->where("mu.first_name LIKE '%$name%'");
$this->db->or_where("mu.last_name LIKE '%$name%'");
与:
为避免出现问题,应使用以下方法:
$this->db->like('mu.first_name', $name);
$this->db->or_like('mu.last_name', $name);
您还可以控制通配符(%)的放置位置
$this->db->like('mu.first_name', $name, 'before');
// Produces: WHERE `mu.first_name` LIKE '%value' ESCAPE '!'
$this->db->like('mu.first_name', $name, 'after');
// Produces: WHERE `mu.first_name` LIKE 'value%' ESCAPE '!'
$this->db->like('mu.first_name', $name, 'both');
// Produces: WHERE `mu.first_name` LIKE '%value%' ESCAPE '!'
查看文档我更改了这行
$this->db->where("mu.first_name LIKE '%$name%'");
$this->db->or_where("mu.last_name LIKE '%$name%'");
对此
$this->db->where("(mu.first_name LIKE '%$name%'");
$this->db->or_where("mu.last_name LIKE '%$name%')");
如果你能以
string
格式传递where
条件更好。它是什么$user\u list=$this->search\u model->userList(a,137,$arr\u friend)代码>您的控制器中有137和a,您能解释一下a,137吗?137已登录用户$arr\u friend is array,其中包含137的朋友。我希望所有的朋友的名字或姓氏中都有“a”
$this->db->where("(mu.first_name LIKE '%$name%'");
$this->db->or_where("mu.last_name LIKE '%$name%')");