2017-02-28 35 views
1

我真的很困惑,需要有人來幫我解釋一下這個問題。php if && || OR語句沒有任何返回......但單獨做

當我單獨使用這些語句2他們得到的結果:

$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']); 

有人能告訴我,我做錯了什麼嗎?感謝所有;-)

+0

是codeignitor? –

+1

它看起來像你試圖通過PHP使用_database_邏輯操作。這不起作用。 '$ ads'變量是什麼類?它可能會暴露方法爲你做'orWhere('country_from','=','something')' –

+0

這聽起來像你*可能*需要添加更多的括號。你可以嘗試'$ ads-> where(('country_to','=',$ _COOKIE ['country_from'])||('country_from','=',$ _COOKIE ['country_from']));'? –

回答

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);