我的请求数据库Active Record有问题
我想创建一个查询:
括号(在WHERE之后和之后4)和'Nadawca','%dor%'
SELECT * FROM (`30px__przesylki`) WHERE ( `test` = 0 AND `Status` = 4 ) AND ( `Nadawca` LIKE '%dor%' OR `Odbiorca` LIKE '%dor%' OR `NrPrzesylki` LIKE '%dor%' OR `Uwagi` LIKE '%dor%' OR `Opis` LIKE '%dor%' OR `Tracking` LIKE '%dor%' OR `Error` LIKE '%dor%' ) ORDER BY `id` asc LIMIT 10
我做CI:
$this->db->order_by("id", "asc");
$this->db->limit($ile,$offset);
$this->db->like('Nadawca', $search);
$this->db->or_like('Odbiorca', $search);
$this->db->or_like('NrPrzesylki', $search);
$this->db->or_like('Uwagi', $search);
$this->db->or_like('Opis', $search);
$this->db->or_like('Tracking', $search);
$this->db->or_like('Error', $search);
$this->db->where('Status', 4);
$query = $this->db->get('przesylki');
收到没有括号的请求:
SELECT *
FROM (`30px__przesylki`)
WHERE `test` = 0
AND `Status` = 4
AND `Nadawca` LIKE '%dor%'
OR `Odbiorca` LIKE '%dor%'
OR `NrPrzesylki` LIKE '%dor%'
OR `Uwagi` LIKE '%dor%'
OR `Opis` LIKE '%dor%'
OR `Tracking` LIKE '%dor%'
OR `Error` LIKE '%dor%'
ORDER BY `id` asc
LIMIT 10
如何制作括号?
答案 0 :(得分:0)
在此处使用:
$sql = "SELECT * FROM 30px__przesylki
WHERE test = 0 AND Status = 4
AND (Nadawca LIKE ? OR Odbiorca LIKE ?
OR NrPrzesylki LIKE ?
OR Uwagi LIKE ?
OR Opis LIKE ?
OR Tracking LIKE ?
OR Error LIKE ? )
ORDER BY id asc
LIMIT 10";
$result = $this->db->query($sql, array($search, $search, $search, $search, $search, $search, $search));
return $result->result_array();
你只需添加限制和偏移量它就可以了!
您可以阅读更多信息here