Hello I'm trying to use concatenation in where clause in codeigniter Equivelent to this in mysql
SELECT * FROM `tblstaff` WHERE concat_ws(' ',firsname,lastname) like '%Firstname lastname%'
I tried doing this in codeigniter , but didn't work
$admin = 'Firstname lastname';
$CI =& get_instance();
$CI->db->where('firstname'.' '.'lastname',$admin);
return $CI->db->get('tblstaff')->row()->default_language;
Any ideas
Not tested but try to change
$CI->db->where('firstname'.' '.'lastname',$admin);
to
$CI->db->where("CONCAT_WS(' ',firsname,lastname) LIKE '%".$admin."%'", NULL, FALSE);
Try codeigniter's query builder $this->db->like
As below:
$admin = 'Firstname lastname';
$CI->db->like("CONCAT_WS(' ',firsname,lastname)",$admin,"both");
For more see here... https://www.codeigniter.com/user_guide/database/query_builder.html#looking-for-similar-data
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.