如何获得彼此不同百分比的两个变量的不同结果

How to get different outcomes of two variables being different percentage to eachother

我有一个包含不同事件的数据库,其中包括最大参与者数 我有一个页面可以向人们展示我们有哪些活动,并且带有 link 到 inscripe 表单。 所有事件的铭文都集中在同一个 table 中,其中有一列记录了它们所铭记的事件。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 稍后用于将 link 更改为 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';
            }