我有一个带有列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个用户的查询?
答案 0 :(得分:0)
尝试以下脚本,然后我更改了。
$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
}