基本上我已经创建了一个通知脚本,我有一个名为notificationCenter.php的页面,管理员用户可以在其中查看所有通知 . 它将显示哪些用户已阅读哪些通知,何时发布以及通过哪些通知 . 一切正常,唯一的问题是当我进入notificationCenter.php页面查看所有通知时,表格不会显示结果 . 但是,我运行if语句来检查是否有任何结果,我没有得到任何错误 . 这是我的代码,我确定我做了一些愚蠢的事情,但我看不出它是什么,我真的很感激任何帮助!

//Get User ID
$id = $_SESSION['user_id'];

//Select * Notifications
$notQuery = $serviceConn->query("SELECT * FROM db759709251.notifications WHERE `not_viewedby` NOT LIKE '%$id%' ");

<h4>Nofication Center</h4>
        <?php if($notQuery->rowCount()) { ?>
          <table>
            <thead>
              <tr>
                <th scope="col">Status</th>
                <th scope="col">User</th>
                <th scope="col">Notification</th>
                <th scope="col">Date</th>
                <th scope="col">Viewed By</th>
                <th scope="col"></th>
              </tr>
            </thead>
            <tbody>
              <?php
                while ($row = $notQuery->fetch()) {
                  $notid = $row['not_id'];
                  $notUser = $row['not_user'];
                  $notMsg = $row['not_msg'];
                  $notStatus = $row['not_status'];
                  $notDate = $row['not_date'];
                  $notViewedby = $row['not_viewedby'];

              ?>
                  <tr>
                    <td style="background-color: <?php echo $statusColour; ?>" data-label="Status"><?php echo $notStatus; ?></td>
                    <td data-label="User"><?php echo $notUser; ?></td>
                    <td data-label="Notification"><?php echo $notMsg; ?></td>
                    <td data-label="Date"><?php echo $notDate; ?></td>
                    <td data-label="Viewed By"><?php echo $notViewedby; ?></td>
                    <td data-label="">
                      <form action="" method="POST">
                        <input type="hidden" name="notificationID" value="<?php echo $notid; ?>" >
                        <input type="hidden" name="notificationBy" value="<?php echo $notViewedby; ?>">
                        <input type="submit" name="read" value="Dismiss!">
                      </form>
                    </td>
                  </tr>
              <?php
                }
              ?>
            </tbody>
          </table>
        <?php } else { ?>
          <p>You currently have no notifications, please check back later.</p>
        <?php } ?>

现在很明显中间有很多HTML用于样式和布局,但我认为它不够重要,因为它不应该对表的输出产生任何影响 . 但正如你可以看到if语句应该打印出没有通知并稍后再回来查看,理论上它应该没有显示的记录 .