1
votes

I have a problem with the request database Active Record.
I would like to create a query:
bracket ( after WHERE and after 4) and '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 

I do in 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');


receives request without brackets:

 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



how to make the brackets?

1

1 Answers

0
votes

Use in this from:

$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();

You just add also the Limits and Offset and it will works!

More info you can read here