Welcome Guest, Not a member yet? Register   Sign In
Problem by select from db when there is a space followed by a comma in where clause
#1

[eluser]Libelle[/eluser]
Hi,

I got the following problem -

I have in my model something like

Code:
$this->db->select('select val from mytable where val like "%'.$where_clause.'%"', FALSE);
echo 'select value from mytable where value like "%'.$where_clause.'%"'; //for control

where clause($where_clause) is a parameter sent to the function. This parameter is a string.

The problem appears if there is a space followed by comma in $where_clause - f.i. 'aaa , bbb'. For any reason CI ignores the first space and string becomes 'aaa, bbb'

I just changed my statement in this way that db error is returned -
Code:
$this->db->select('select val1 from mytable where val like "%'.$where_clause.'%"', FALSE);
there is no val1 column I I get error
Code:
A Database Error Occurred

Error Number: 1054

Unknown column 'val1' in 'field list'

Then sql statement is dumped. And here I see that the statement is
Code:
select value from mytable where value like '%ааа, bbb%'

It must be

Code:
select value from mytable where value like '%ааа , bbb%'

One space was cutted and as a result it returns no rows.

$where_clause is sent to the function with the spaces - this could be verified by echoing the variable.
If I use
Code:
$this->db->from('mytable');
$this->db->like('val', $where_clause);
$query = $this->db->get();

it works like a charm. But I have quite complex sql query and have to use
Code:
$this->db->select

Any ideas what could be wrong?


Messages In This Thread
Problem by select from db when there is a space followed by a comma in where clause - by El Forum - 02-16-2012, 09:10 AM



Theme © iAndrew 2016 - Forum software by © MyBB