问题描述
我有一个包含不同事件的数据库,其中包括最大参与者数 我有一个页面,向人们展示我们有哪些活动,并带有指向铭文表格的链接。 所有事件的铭文都集中在同一个表中,并列有它们所铭刻的事件。ATM 显示有多少地方以及有多少人已经订阅了。如果铭文数量等于最大参与者数量,它也会阻止新的铭文。如下所示:
<h2 class="title">
<?PHP
//display eventname
$sql = "SELECT eventname FROM events WHERE id=1";
$data = $conn->query($sql);
if ($data->num_rows > 0) {
while($event = $data->fetch_assoc()) {
echo $event["eventname"];
$eventname = $event["eventname"];
}
}
?>
</h2>
<h2 style="color:red;">
<?PHP
//display registered participants
$sql = ("SELECT COUNT(*) FROM eventregistrations WHERE eventname='$eventname'");
$rs = MysqLi_query($conn,$sql);
$result = MysqLi_fetch_array($rs);
echo $result[0].'/';
$numberparticipants = $result[0];
// display max participants
$sql = "SELECT maxparticipants FROM events WHERE id=1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {
while($row = $result->fetch_assoc()) {
echo $row["maxparticipants"];
$maxparticipants = $row["maxparticipants"];
}
}
?>
</h2>
$numberparticipants 和 $maxparticipants 稍后用于更改到 inscripeform 的链接
我想要实现的是页面没有显示确切的数字,而只是显示事件的完整程度。类似的东西
if ($numberparticipants < 80% of $maxparticipants) {
echo 'free places';
} else if ($numberparticipants BETWEEN 80% of $maxparticipants AND $maxparticipants ) {
echo 'almost full';
} else {
echo 'full';
}
谢谢 博杰
解决方法
为什么不喜欢
$eightyPercent = intval(0.8 * $maxparticipants);
if($eightyPercent < $numberparticipants && $numberparticipants < $maxparticipants){
echo 'almost full';
}
,
$sql = ("SELECT COUNT(*) FROM registrations WHERE eventname='$eventname'");
$rs = mysqli_query($conn,$sql);
$result = mysqli_fetch_array($rs);
$numberparticipants = $result[0];
$sql = "SELECT maxparticipants FROM events WHERE id=1";
$result = $conn->query($sql);
if ($result->num_rows > 0) {while($row = $result->fetch_assoc()) {
$maxparticipants = $row["maxparticipants"];}}
$p80maxparticipants = ($maxparticipants *0.8);
if ($numberparticipants < $p80maxparticipants) {
echo 'Open for inscription';
}else if ($numberparticipants >= $p80maxparticipants && $numberparticipants < $maxparticipants) {
echo 'allmost full';
}else if ($numberparticipants == $maxparticipants) {
echo 'Volzet';
}else{
echo 'error';
}