Welcome Guest, Not a member yet? Register   Sign In
composing sql command
#1

[eluser]Unknown[/eluser]
Hi guys,
I need to write this sql in CI:

Code:
SELECT * FROM product WHERE
`producer_id` = '1' AND
(`name` LIKE '%q%' OR `content` LIKE '%q%' )
ORDER BY `name` asc LIMIT 2



as you see, I have data from search-form with 2 variables - producer_id and q (some searched value).

If I use this code, I get sql command without brackets (and that´s wrong):
Code:
$this->db->where('producer_id', $search['producer_id']);
$this->db->or_where('name LIKE', $search['q']);
$this->db->or_where('content LIKE', $search['q']);

$this->db->order_by('name', 'asc')->get('product', $limit, $offset)->result_array();

Code:
SELECT * FROM product WHERE
`producer_id` = '1' AND
`name` LIKE '%q%' OR `content` LIKE '%q%'
ORDER BY `name` asc LIMIT 2

do you have any suggestions how to do this?
thank you


Messages In This Thread
composing sql command - by El Forum - 07-20-2012, 06:47 AM
composing sql command - by El Forum - 07-20-2012, 06:34 PM
composing sql command - by El Forum - 07-22-2012, 09:29 AM



Theme © iAndrew 2016 - Forum software by © MyBB