php if&& || OR语句什么都不返回......但是单独做

时间:2017-02-28 20:23:13

标签: php if-statement

我真的很困惑,需要有人为我解释这件事。

当我分别使用这两个语句时,他们会得到结果:

$ads->where('country_to', '=', $_COOKIE['country_from'])

$ads->where('country_from', '=', $_COOKIE['country_from']);

...但是一旦我尝试使用OR语句,我就没有结果,只是想知道为什么?

$ads->where('country_to', '=', $_COOKIE['country_from']) || $ads->where('country_from', '=', $_COOKIE['country_from']);

我也试过这种方式,也没有结果:

$ads->where('country_to', '=', $_COOKIE['country_from'] || 'country_from', '=', $_COOKIE['country_from']);

有人可以告诉我这里我做错了什么吗?谢谢大家; - )

1 个答案:

答案 0 :(得分:1)

好像您正在使用Codeignitor,如果是,请使用orWhere()

$ads->where('country_to', '=', $_COOKIE['country_from']);

$ads->orwhere('country_from', '=', $_COOKIE['country_from']);// or try or_where

或者

$select = "country_to = '".$_COOKIE['country_from']."' OR country_from = '".$_COOKIE['country_from']."'";

$ads->where($select);

或者

$country_from = $_COOKIE['country_from'];

$select = "country_to = $country_from OR country_from = $country_from";

$ads->where($select);