如何将sql中每天的预订数量限制为50个用户

jqjz2hbq  于 2021-06-15  发布在  Mysql
关注(0)|答案(1)|浏览(300)

我有一个列表 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个用户?

efzxgjgh

efzxgjgh1#

尝试下面的脚本,我改变了。

$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
}

相关问题