我正在尝试为用户提供数据库中的无限选项,但是我不确定如何执行此操作。我将默认值设置为10,因为它们有10个视图,并且对于它们正在查看的每个页面,它都会递减计数。一旦达到0,用户将不得不再次注册,除非他们已经付款但不确定如何使观看次数不受限制
我对此处的操作感到困惑,因为找不到任何将视图设置为无限制的选项。
<?php
include_once 'navbar.php';
if(!$_SESSION['u_uid']) {
header("Location: index.php?medical_subscriptionplan_process=notlogin");
exit();
} else {
include_once 'includes/dbh.php';
if(isset($_POST['submit'])) {
$views = strip_tags($_POST['subscriptionplan']);
if ($views == '') {
header("Location: index.php?medical_subscriptionplan_process=emptied");
exit();
} else {
if ($views == '10_views') {
$views = 10;
$sql = "UPDATE users
SET views = ?
WHERE user_uid = ?;
";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "is", $views, $_SESSION['u_uid']);
mysqli_stmt_execute($stmt);
}
} else {
if ($views == '100_views') {
$views = 100;
$sql = "UPDATE users
SET views = ?
WHERE user_uid = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "is", $views, $_SESSION['u_uid']);
mysqli_stmt_execute($stmt);
}
} else {
if ($views == 'unlimited') {
$views = NULL;
$sql = "UPDATE users
SET views = ?
WHERE user_uid = ?;";
$stmt = mysqli_stmt_init($conn);
if(!mysqli_stmt_prepare($stmt, $sql)) {
echo "SQL error";
} else {
mysqli_stmt_bind_param($stmt, "is", $views, $_SESSION['u_uid']);
mysqli_stmt_execute($stmt);
}
}
}
}
header("Location: index.php?medical_subscriptionplan_process=sucess");
}
}
}
答案 0 :(得分:1)
要表示数据库中无限制的视图,只需在数据库视图列中添加-1,否则用其他正整数设置它,然后检查条件,
if (views == -1){
// user has paid for unlimited view
}
答案 1 :(得分:0)
您可以在数据库中添加标志(就像“ is_unlimited”一样)以检查客户访问限制
if($isunlmited==1){
//always allow access
}else{
//check for 10_views limit
}