我有一个列为id autoincrement, username, datetime, logtime(on update)
的表
我想每天只允许50位用户进行预订
并且每个用户每天都要进行一次预订。
如何编写查询?
我针对用户每天写过一次有关此查询的查询
$con = mysqli_connect($host, $db_username, $db_password, $db_name);
if ($con) {
mysqli_select_db($con, $db_name) or die('Database not found');
$sql = "SELECT COUNT(1) FROM `booker` WHERE `datetime` >= DATE_SUB(NOW(), INTERVAL 1 DAY)";
$result = mysqli_query($con, $sql);
}
如何编写查询,每天只允许50个用户?
最佳答案
试试下面的脚本,我改变了。
$sql = "SELECT * FROM `booker` WHERE DATE(`datetime`) = CURDATE()";
$result = mysqli_query($con, $sql);
//get total records
$num_rows = mysqli_num_rows($result);
if($num_rows>50)
{
//Today booked orders is completed
}
else
{
//The booked orders is not completed for today
}
关于php - 如何将每天在SQL中的预订数量限制为50个用户,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/54060293/