我在我的页面中订购项目时遇到了问题。我想要的项目是随机排序,但每天都会改变。我使用ORDER by rand()代码,并在()中希望显示todays日期。例如,如果今天是2020年12月10日,我想在我的代码中按rand(10)排序。这是我的代码
include("pagination/function.php");
$page = (int) (!isset($_GET["page"]) ? 1 : $_GET["page"]);
$limit = 12; //if you want to dispaly 10 records per page then you have to change here
$startpoint = ($page * $limit) - $limit;
$statement = "product ORDER by rand()"; //you have to pass your query over here
$res=mysqli_query($link,"select * from product {$statement} LIMIT {$startpoint} , {$limit}");
while ($row=mysqli_fetch_array($res))
{发布于 2020-12-11 06:55:00
您声明要传递今天的10,但是随机顺序将在每年每个月的第10天相同。如果你希望每一天都是随机的,那么使用UNIX时间戳:
$seed = time();
$statement = "product ORDER by rand($seed)";如果你真的想要一个月中的第几天,那么获取日期数字:
$seed = date("j");
$statement = "product ORDER by rand($seed)";您也许可以使用MySQL Date and Time Function,但我从未在RAND()中尝试过它们。
https://stackoverflow.com/questions/65243375
复制相似问题