簡體   English   中英

嘗試從SQL字段設置PHP變量

[英]Trying to set php variable from sql field

嘗試在SortingMethodId等於3、6或7的情況下設置show_hours為true的變量。現在,僅當SortingMethodId等於3(來自MySQL數據庫)時,它才如下所示:

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

所以我嘗試了:

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

並只返回了一個錯誤...。 我只是一個初學者,試圖對我們應用程序中的一些現有代碼進行哈希處理,所以很容易:)

嘗試:

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

您必須重復var。

也許你可以嘗試像...

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM