这里我要显示的是bookrentalinfo表记录必须借还的字段(renewaldate)必须小于currentdate。 但是在这里我无法显示那些必须按小于当前日期的字段返回的记录,你能建议我需要把这个条件放在哪里才能正常工作吗,提前谢谢你。
我的文件mail.php
<?php
include('db/db.php');
include('assets/page_header.php');
?>
<?php
$currentdate=date("H:i:s");
echo $currentdate;
$str="select * from bookrentalinfo where status='BORROWED' ";
$query=mysql_query($str);
echo "<table border='1'>";
echo "<tr><th>BookId</th><th>MemNo</th><th>RentedOn</th><th>ToBeReturnedBy</th><th>ActualReturnDate</th><th>Status</th></tr>";
while($res=mysql_fetch_array($query))
{
if($res['tobereturnedby']<=$currentdate)
{
echo "<tr>";
echo "<td>".$res['bookid']."</td>";
echo "<td>".$res['memno']."</td>";
echo "<td>".$res['rentedon']."</td>";
echo "<td>".$res['tobereturnedby']."</td>";
echo "<td>".$res['actualreturndate']."</td>";
echo "<td>".$res['status']."</td>";
echo "</tr>";
}
}
echo "</table>";
?>
最佳答案
您的时间戳格式可能不匹配,因此 if 语句中的比较未正确过滤。解决此问题取决于您的查询返回的内容:
如果
$res['tobereturnedby']
返回 UNIX timestamp ,然后将您的$currentdate
也设置为一个:$currentdate = time();
如果
$res['tobereturnedby']
返回 MySQL timestamp ,然后将您的$currentdate
设置为匹配的内容:$currentdate = date('YYYY-MM-DD HH:MM:SS')
注意:在这种情况下,您应该在进行比较之前从两个比较值中去除所有非数字字符。您可以使用
filter_val()
或str_replace()
这样做。
关于php - SQL 查询中的显示不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42711808/