[eluser]xcristi[/eluser]
Hello,
I need to use a LIKE sql statement in CI. I use Active Records, so I have
Code:
$this->db->like('ci_name', strtoupper($id));
and this generates code like '%$id%'... OK.
My question is: it there a posibility to generate code like '$id%' or '%$id' (without % on both sides) ?
If not, I think I must recode some functions in DB_active_rec.php like below:
Code:
function like($field, $match = '', $side)
{
return $this->_like($field, $match, 'AND ', $side);
}
The same for orlike() function.
Code:
function _like($field, $match = '', $type = 'AND ', $side = 3)
{
if ( ! is_array($field))
{
$field = array($field => $match);
}
foreach ($field as $k => $v)
{
$prefix = (count($this->ar_like) == 0) ? '' : $type;
$v = $this->escape_str($v);
switch ($side) {
case 1 : $this->ar_like[] = $prefix." $k LIKE '%{$v}'";break;
case 2 : $this->ar_like[] = $prefix." $k LIKE '{$v}%'";break;
case 3 : $this->ar_like[] = $prefix." $k LIKE '%{$v}%'";break;
}
}
return $this;
}
where 1 means left; 2 means right and 3 means both sides.
What do you think about this?
Thanks.