下午好,所以我想檢查我的數據庫中的特定值在CakePHP中是否爲真。
我的SQL表稱爲口腔看起來像這樣CakePHP檢查數據庫中的特定值是否爲真
---------------------
|PK|OralPresentation|
---------------------
|1 |1 |
---------------------
所以,我想在我的控制做的是檢查,如果該值是OralPresentation是1
我在下面的代碼這樣做
$OralStatus = $this->Submission->query("SELECT * FROM Oral;");
//If Oral Presentations are activated
if($OralStatus['0']['PK']['OralPresentation']==1)
{
$this->set('Istrue','true'); //Passing this information to the view.
}
else
{
$this->set('Istrue','false');
}
}
現在,當我在我看來呼應IsTrue運算它總是儘管數據庫表爲1。另一種解決方法我都試過返回false是在IF語句
if($OralStatus['0']['PK']['OralPresentation'])
所以我會在IF語句上面插入代碼? 第一行陳述位置 第二行我檢查第二行 位置1處的Oralpresentation,我瞭解其他所有內容,但是Compact有什麼作用? –
Compact創建一個包含變量及其值的數組。所以你可以用'$ this-> set(compact('Istrue'));''來爲你的視圖設置'$ Istrue'的值。或者,你可以用'$ this-> set('Istrue',$ Istrue);'替換if語句。 – bill
我可能不得不保留IF,因爲如果它是真的,我想在視圖中創建一個鏈接。這就是爲什麼我通過價值 感謝您的幫助! –