dongpiansui8755 2014-10-17 17:56
浏览 49

带括号的CodeIgniter Active Record

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条回答 默认 最新

  • duanjia8215 2014-10-17 19:49
    关注

    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

    评论

报告相同问题?

悬赏问题

  • ¥15 python的qt5界面
  • ¥15 无线电能传输系统MATLAB仿真问题
  • ¥50 如何用脚本实现输入法的热键设置
  • ¥20 我想使用一些网络协议或者部分协议也行,主要想实现类似于traceroute的一定步长内的路由拓扑功能
  • ¥30 深度学习,前后端连接
  • ¥15 孟德尔随机化结果不一致
  • ¥15 apm2.8飞控罗盘bad health,加速度计校准失败
  • ¥15 求解O-S方程的特征值问题给出边界层布拉休斯平行流的中性曲线
  • ¥15 谁有desed数据集呀
  • ¥20 手写数字识别运行c仿真时,程序报错错误代码sim211-100