如何使视图准确倒数

时间:2018-12-24 08:44:38

标签: php mysql

我试图让用户每次访问页面的查看部分时的观看次数减一,并在帐户达到0时删除其帐户。我的问题是,如果我使用$可以使它正常工作视图,但是当我使用$ row2 ['views']时不可以。我只想知道你们是否也有同样的问题?看来,当我使用$ row2 ['views']时,它会跳几个数字,而不是每次都减去一个。

我想这可能有点重复,但我尝试使用变量$ row2,但只能在使用$ views时使其工作。

<?php

include_once 'navbar.php';

echo '<div class="medical_review_view_welcome">
     <h1>Welcome '.$_SESSION['u_uid'].' to your Medical Viewing page</h1>
     </div>';
if(!$_SESSION['u_uid']) {
    header("Location: index.php?medical_review_view=notlogin");
    exit();
} else {
    include_once 'includes/dbh.php';



}
     $sql = "SELECT * FROM review;";

      $stmt = mysqli_stmt_init($conn);
                        if(!mysqli_stmt_prepare($stmt, $sql)) {
                           echo "SQL error";
                        } else {
                          mysqli_stmt_execute($stmt);
                          $result = mysqli_stmt_get_result($stmt);
                          $resultCheck = mysqli_num_rows($result);
                          $row = mysqli_fetch_assoc($result);

                          if ($resultCheck < 1) {
                             echo '<div class="no_results">Please be patient as there are no results currently available</div>';
                          }

                          echo '<table class="medical_review_view">
                      <tr>
                      <th colspan="2" class="update_title">Welcome to the Medical Review View Result</th>
                      </tr>';



                         while($row = mysqli_fetch_assoc($result)) {

                         echo '<tr><th>Clinic Name:</th><td>'.$row['clinic_name'].'</td>
                               <tr><th>Clinic Address:</th><td>'.$row['clinic_address'].'</td>
                               <tr><th>Clinic Number:</th><td>'.$row['clinic_number'].'</td>
                               <tr><th>Are you a?</th><td>'.$row['type_of_profession'].'</td>
                               <tr><th>Services:</th><td>'.$row['services'].'</td>
                               <tr><th>Recommended Doctors:</th><td>'.$row['doctors'].'</td>';


                         }


                             $sql2 = "SELECT * FROM users WHERE user_uid = ?;";
                         $stmt = mysqli_stmt_init($conn);
                        if(!mysqli_stmt_prepare($stmt, $sql2)) {
                           echo "SQL error";
                        } else {
                          mysqli_stmt_bind_param($stmt, "s", $_SESSION['u_uid']);
                          mysqli_stmt_execute($stmt);
                          $result2 = mysqli_stmt_get_result($stmt);
                          $resultCheck2 = mysqli_num_rows($result2);
                          $row2 = mysqli_fetch_assoc($result2);
                          $views = $row2['views'];
                          $views = $views - 1;



                          $sql3 = "UPDATE users
                                   SET views = ?
                                   WHERE user_uid = ?;
                                  ";


              if (!mysqli_stmt_prepare($stmt, $sql3)) {
          echo 'SQL statement failed';
        } else {
      //Bind parameters to the placeholder
      mysqli_stmt_bind_param($stmt, "is",$views, $_SESSION['u_uid']);
      //Run parameters inside database
      mysqli_stmt_execute($stmt);

                       echo '<tr><th>View Remaining:</th><td>'.$views.'</td>
                            </table>';  

       if ($views == 0) {
          $sql4 = "DELETE FROM users WHERE user_uid = ?;";

          if (!mysqli_stmt_prepare($stmt, $sql4)) {
          echo 'SQL statement failed';
        } else {
      //Bind parameters to the placeholder
      mysqli_stmt_bind_param($stmt, "s", $_SESSION['u_uid']);
      //Run parameters inside database
      mysqli_stmt_execute($stmt);

      session_unset();
      session_destroy();

      echo "<meta http-equiv='refresh' content='0; index.php?medical_review_view=accountdeleted'>";
      exit();
       }                  

}
}
}
}

0 个答案:

没有答案