【问题标题】:Perform WHERE != in CodeIgniter Activerecord在 CodeIgniter Activerecord 中执行 WHERE !=
【发布时间】:2014-10-23 02:20:10
【问题描述】:

如何在 CodeIgniter Activerecord 中执行WHERE column != 100001?抱歉,我找不到任何关于此的消息来源。

我的查询是

$this->db->select('friend, username, fullname, profile_pic')
                        ->from('friends')
                        ->join('user_info', 'user_info.id = friend')
                        ->where('user', $my->id)
                        ->where('status', '1')
                        ->get()->result_object();

我要加->where('friend' != 10001)

【问题讨论】:

    标签: php mysql codeigniter activerecord


    【解决方案1】:

    永远记住第二个参数是值:

    ->where('friends.friend !=', 10001)
    

    是的,这在active record manual 上有很好的记录。

    它在 ->where() 方法的 Custom key/value method: 部分。

    【讨论】:

    • 谢谢..它有效。为什么我从来没有想过这个?
    【解决方案2】:

    我知道两种方法,首先在变量中声明你的语法。这是代码

    $where = "user='".$my->id."' AND status='1' AND friend !=10001";
    
    $this->db->where($where);
    

    或者使用这个

    $this->db->where('friend !=', 10001);
    

    【讨论】:

      猜你喜欢
      • 2015-03-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-03-12
      相关资源
      最近更新 更多