我已经尝试了所有这些方法,但它不起作用......
if ($row['dropdate1'] == "".$datemon."" || $row['dropdate1'] == "".$datetue."" || $row['dropdate1'] == "".$datewed."" || $row['dropdate1'] == "".$datethu."" || $row['dropdate1'] == "".$datefri."") {}
if ($row['dropdate1'] == ".$datemon." || $row['dropdate1'] == ".$datetue." || $row['dropdate1'] == ".$datewed." || $row['dropdate1'] == ".$datethu." || $row['dropdate1'] == ".$datefri.") {}
if ($row['dropdate1'] == "$datemon" || $row['dropdate1'] == "$datetue" || $row['dropdate1'] == "$datewed" || $row['dropdate1'] == "$datethu" || $row['dropdate1'] == "$datefri") {}
if ($row['dropdate1'] == $datemon || $row['dropdate1'] == $datetue || $row['dropdate1'] == $datewed || $row['dropdate1'] == $datethu || $row['dropdate1'] == $datefri) {}
更新:
这个问题与数据库查询和获取正确记录无关。正确的记录已经显示。这是关于html表格中的记录如何显示在html/php页面上。
如果记录有 1 个删除日期,则仅显示一行。
如果记录有 2 个删除日期,那么它将在表中显示为 2 行。
如果记录有 6 个删除日期,则最多可达 6 行。
因此,如果只有一个删除日期等于我上面提到的 php 变量之一,我只想显示该行,但会显示该记录的所有删除日期行。
假设 $datethu = 01-23-2014 并且该日期位于任意 dropdate 字段下的记录之一中,假设为 dropdate4。
表格将显示如下:
drop id company jobname dropdate bunch-of-other-columns
1 260 abc whatever 01-02-2014 ...
2 260 abc whatever 01-09-2014 ...
3 260 abc whatever 01-16-2014 ...
4 260 abc whatever 01-23-2014 ...
5 260 abc whatever 01-30-2014 ...
6 260 abc whatever 02-06-2014 ...
如果所有 dropdate 都是 php 变量之一,则上述内容是准确的。但由于只有一个 dropdate 包含 php 变量之一,因此该表应如下所示:
drop id company jobname dropdate bunch-of-other-columns
4 260 abc whatever 01-23-2014 ...
最佳答案
将所有可能的值放入一个数组中,然后使用 in_array()
:
$values = array($datemon, $datetue, $datewed, $datethu, $datefri);
if (in_array($row['dropdate1'], $values)) {
// we have a match
}
关于php - 一个 mysql 字段可以等于多个 php 变量的 php 规则是如何编写的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21293721/