如何只显示一次resultcheck消息

时间:2019-01-10 06:00:47

标签: php

我有以下代码,但是目前我遇到的主要问题是,如果未找到结果,它将继续显示resultcheck2的消息。我的问题是,如果我有10位学生订阅了该课程计划,那么它将打印出10则信息,而不是10则。有没有办法将其减少到一个?

<?php


include_once __DIR__.'/header2.php';
if(!isset($_SESSION['u_uid'])) {
   echo "<meta http-equiv='refresh' content='0;url=index.php?level1promo=notlogin'>";
    exit();
} else {
    if($_SESSION['u_permission'] == 0) {
        echo "<meta http-equiv='refresh' content='0;url=header2.php?level1promo=nopermission'>";
        exit();
    } else {
    include_once __DIR__. '/includes/dbh.php';
    $reward_points = 300;
    $sql = "SELECT * FROM rewards WHERE reward_points > ?;";

    $stmt = mysqli_stmt_init($conn);
     //Prepare the prepared statement
     if (!mysqli_stmt_prepare($stmt, $sql)) {
        echo 'SQL statement failed';
     } else {
     //Bind parameters to the placeholder
     mysqli_stmt_bind_param($stmt, "i", $reward_points);
      //Run parameters inside database
     mysqli_stmt_execute($stmt);
     $result = mysqli_stmt_get_result($stmt);
     $resultCheck = mysqli_num_rows($result);

      if ($resultCheck < 1) {

      echo '<div class="admin_nolevel2promo">There are no students who qualified for this promotion yet due to the lack of points!</div>';
      exit();
     } else {

     $rowCounter = 0;

     while($row = mysqli_fetch_assoc($result)) {
        $username = $row['user_uid'];

     $rowCounter++;


      $sql2 = "SELECT * FROM memberships WHERE user_uid = ? AND subscriptionplan2 IS NULL;";

          $stmt = mysqli_stmt_init($conn);
     //Prepare the prepared statement
     if (!mysqli_stmt_prepare($stmt, $sql2)) {
        echo 'SQL statement failed';
     } else {
     //Bind parameters to the placeholder
     mysqli_stmt_bind_param($stmt, "s", $username);
      //Run parameters inside database
     mysqli_stmt_execute($stmt);
     $result2 = mysqli_stmt_get_result($stmt);
     $resultCheck2 = mysqli_num_rows($result2);

     if($resultCheck2 < 1) {
         echo '<div class="admin_alreadylevel2">There might be some students who have not qualified for this promotion yet because they already have subscribed for Level 2!</div>';
       } else {


         echo '<table class="admin_level2promo">

           <tr>
           <th colspan="2" class="update_title">Welcome to the Administrator\'s Level 2 Promo Competition\' Section</th>
           </tr>';


     while($row2 = mysqli_fetch_assoc($result2)) {
         if($row2['subscriptionplan2'] == null) {
             $subscriptionplan = 'Yes';
         }
         echo '<tr>
                      <th>Result No:</th><td>',htmlspecialchars($rowCounter),'</td>
                      </tr>
                      <tr>
                      <th>ID:</th><td>',htmlspecialchars($row['id']),'</td>
                      </tr>
                      <tr>
                      <th>Username:</th><td>',htmlspecialchars($row['user_uid']),'</td>
                      </tr>
                      <tr>
                      <th>First Name:</th><td>',htmlspecialchars($row['first_name']),'</td>
                      </tr>
                      <tr>
                      <th>Last Name:</th><td>',htmlspecialchars($row['last_name']),'</td>
                      </tr>
                      <tr>
                      <th>Reward Points:</th><td>',htmlspecialchars($row['reward_points']),'</td>
                      </tr>
                      <tr>
                      <th>Bronze:</th><td>',htmlspecialchars($row['bronze']),'</td>
                      </tr>
                      <tr>
                      <th>Silver:</th><td>',htmlspecialchars($row['first_name']),'</td>
                      </tr>
                      <tr>
                      <th>Gold:</th><td>',htmlspecialchars($row['gold']),'</td>
                      </tr>
                      <tr>
                      <th>Rank:</th><td>',htmlspecialchars($row['rank']),'</td>
                      </tr>
                      <tr>
                      <th>Qualified for promotion:</th><td>',htmlspecialchars($subscriptionplan),'</td>
                      </tr>';
     }

    }
}
}
echo '</table>';
}
}
}
}


?>

0 个答案:

没有答案