使用UNIX_TIMESTAMP一周

时间:2013-11-25 08:35:46

标签: php unix-timestamp

我得到了从星期一到星期五按日期显示帖子的代码,但我发布的代码显示我发布的上一篇文章

<?php
    $query = mysqli_query($c, 'SELECT c.chapter, n.name, n.img FROM chapters AS c LEFT JOIN novels AS n ON c.novel = n.id WHERE c.time <= unix_timestamp()');
    while($row = mysqli_fetch_row($query)):
?>

有人可以告诉我,我必须使用哪些代码来显示星期一到星期五的发布帖子吗?

我试试这个,服务器时间是第25天我没有得到结果而且我最少有显示1个帖子

$query = mysqli_query($c, 'SELECT c.chapter, n.name, n.img FROM chapters AS c LEFT JOIN novels AS n ON c.novel = n.id WHERE FROM_UNIXTIME(c.time,\'%N\')>=1 AND FROM_UNIXTIME(c.time,\'%N\')<=5'); 

现在用这个

修复
$query = mysqli_query($c, 'SELECT c.chapter, n.name, n.img FROM chapters AS c LEFT JOIN novels AS n ON c.novel = n.id WHERE DAYOFWEEK(FROM_UNIXTIME(c.time))>=1 AND DAYOFWEEK(FROM_UNIXTIME(c.time))<=5'); 
while($row = mysqli_fetch_row($query)):
?>

1 个答案:

答案 0 :(得分:1)

您可以通过此

获取日期名称
SELECT DAYNAME(CURDATE()), DAYNAME(DATE_ADD(CURDATE(), INTERVAL 4 DAY)); 

OR

SELECT DAYNAME('2013-11-25'), DAYNAME(DATE_ADD('2013-11-25', INTERVAL 4 DAY)); 

希望它对你有所帮助。