Welcome Guest, Not a member yet? Register   Sign In
Embedding wildcard '%' into a query string
#1

[eluser]Unknown[/eluser]
I am doing a search query

Code:
// Prepare query string
//$searchstr = preg_replace('/\s{1,}/', '%', $searchstr);
  
$query = $this->db->select()
->from('employee')
->like("CONCAT(fname,' ',lname)", $searchstr)
->or_like('phone', $searchstr)
->order_by('lname','fname')
->get();

But when I uncomment the preg_replace line, the '%' get escaped in the call. I have tried %% also to no avail.

Any suggestions?
#2

[eluser]DarkManX[/eluser]
http://ellislab.com/codeigniter/user-gui...tml#select
look up for $this->db->like();
#3

[eluser]Unknown[/eluser]
Thanks. I'm well aware of the documentation covering like. The problem is that if I add the wildcard %, it escapes it: (from the log)

Code:
ERROR - 2012-08-20 13:02:15 --> Query: SELECT *
FROM (`mytable`)
WHERE  CONCAT(fname,' ',lname)  LIKE '%j\%doe%'
OR  `phone`  LIKE '%j\%doe%'
ORDER BY `lname` ASC
or similarly
Code:
RROR - 2012-08-20 13:04:00 --> Query: SELECT *
FROM (`mytable`)
WHERE  CONCAT(fname,' ',lname)  LIKE '%j\%\%doe%'
OR  `phone`  LIKE '%j\%\%doe%'
Do you know how to prevent it from escaping the % in the middle?




Theme © iAndrew 2016 - Forum software by © MyBB