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

查看:18
本文介绍了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.我希望 or 仅限于 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天全站免登陆