我有一个选择框,其中包含"全部"选项,然后是用户列表。
我正在努力的是创造这样的东西。 除了尝试查询数据库以检查变量是否在数据库中之外,我拥有大部分内容。
if ($variable == 'All') { code here }
else if ($variable != 'ALL' != *[result in database]*) { code here }
else { code here }
除了尝试查询数据库以检查变量是否在数据库中之外,我拥有大部分内容。
如何将 mySQL 数据库的查询合并到我的 if 语句中的任何建议。
谢谢
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 }