I have a database with different events which includes the max number of participants I have a page that shows people what events we have, and with a link to the inscripe form. The inscriptions of all events come together in the same table with a column of what event they inscriped in. ATM it shows how many places there are and how many people have subscribed already. It also blocks new inscriptions if the number of inscriptions is equal to the max number of participants. This looks as follows:
<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 and $maxparticipants are used later to alter the link to the inscripeform
What I want to achieve is that the page doesn’t show exactly the number, but just the idea of how full the event is. Something like
if ($numberparticipants < 80% of $maxparticipants) { echo 'free places'; } else if ($numberparticipants BETWEEN 80% of $maxparticipants AND $maxparticipants ) { echo 'almost full'; } else { echo 'full'; }
Thx Beau-Jay
Advertisement
Answer
Why not something like
$eightyPercent = intval(0.8 * $maxparticipants); if($eightyPercent < $numberparticipants && $numberparticipants < $maxparticipants){ echo 'almost full'; }