Codeigniter的`where`和`or_where` [英] Codeigniter's `where` and `or_where`

查看:341
本文介绍了Codeigniter的`where`和`or_where`的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要在我的模型中指定查询

I'm trying to specify a query in my model

$this->db
        ->select('*')
        ->from('library')
        ->where('library.rating >=', $form['slider'])
        ->where('library.votes >=', '1000')
        ->where('library.language !=', 'German')
        ->where('library.available_until >=', date("Y-m-d H:i:s"))
        ->or_where('library.available_until =', "00-00-00 00:00:00")
        ->where('library.release_year >=', $year_start)
        ->where('library.release_year <=', $year_end)
        ->join('rating_repo', 'library.id = rating_repo.id')

是与我的 or_where 。我希望仅限于 available_until 字段。然而,目前,我得到的结果,有一种德语,这不是我想要的语言。如何将我的 or_where 过滤器限制到 available_until 字段?

So, the trouble i'm having is with my or_where. I want the or to be restricted to only the available_until field. Currently, however, i'm getting results which have a language of German which isn't what i want. How do i restrict my or_where filter to the available_until field only?

推荐答案

您只能修改两行:

->where('(library.available_until >=', date("Y-m-d H:i:s"), FALSE)
->or_where("library.available_until = '00-00-00 00:00:00')", NULL, FALSE)

编辑:

省略 FALSE 参数会将反引号放在括号之前,并使它们成为表名/值的一部分,使查询无法使用。

Omitting the FALSE parameter would have placed the backticks before the brackets and make them a part of the table name/value, making the query unusable.

NULL 参数只是因为该函数需要第二个参数是一个值,因为我们没有一个,我们发送NULL。

The NULL parameter is there just because the function requires the second parameter to be a value, and since we don't have one, we send NULL.

这篇关于Codeigniter的`where`和`or_where`的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆