簡體   English   中英

if / else if / else與查詢數據庫產生假。

[英]If / else if / else with query to a database resulting false.

我有一個選擇框,其中包含所有選項,然后是用戶列表。

我正在努力創建這樣的東西。 除了試圖查詢數據庫以檢查變量是否在數據庫中之外,我大部分都擁有。

   if ($variable == 'All') { code here }

   else if ($variable != 'ALL' != *[result in database]*) { code here }

   else { code here }

除了試圖查詢數據庫以檢查變量是否在數據庫中之外,我大部分都擁有。

關於如何在if語句中合並mySQL數據庫查詢的任何建議。

謝謝

if ($variable == 'All') {
 ... do something ...
} else {
   $sql = "SELECT ...";
   $result = mysql_query($sql) or die(mysql_error());
   $row = mysql_fetch_assoc($result);
   if ($row['somefield'] == 'whatever') {
       ... do something else ...
   } else {
       ... do something even "elser" ...
   }
}

您不能使用這樣的運算符。

更換:

else if ($variable != 'ALL' != *[result in database]*) { code here }

帶有:

else if ($variable != 'ALL' AND $variable != *[result in database]*) { code here }

暫無
暫無

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

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