2012-12-07 23 views
0

如果SortingMethodId等於3,6或7,則嘗試設置show_hours爲true的變量。現在只有當SortingMethodId等於3(來自MySQL數據庫)時才如此,如下所示:嘗試從sql字段設置php變量

$this->data["show_hours"] = ($company->getSortingMethodId() == 3); 

所以,我想:

$this->data["show_hours"] = ($company->getSortingMethodId() == 3 OR == 6 OR == 7); 

,只返回一個錯誤....想法?我只是想湊了在我們的應用中的一些現有的代碼是初學者,所以很容易:)

+0

在發佈未來出現的問題,請記住,包括錯誤說什麼,因爲這將在確定問題:) – Ren

回答

1

嘗試用:

$sortingMethodId = $company->getSortingMethodId(); 
$this->data["show_hours"] = ($sortingMethodId == 3 || $sortingMethodId == 6 || $sortingMethodId == 7); 

必須重複變種。

+0

完善幫助用戶!正是我在找的東西。 Thx – firecasey

+0

不客氣! :) – jan267

0

也許你可以嘗試這樣...

$sortingMethodId = $company->getSortingMethodId(); 
$this->data["show_hours"] = $sortingMethodId == 3 ? true : ($sortingMethodId == 5 ? true : ($sortingMethodId == 7 ? true : false));