IS NOT NULL不消除null值

时间:2020-06-12 20:08:21

标签: php sql

我想从数据库中获取数据。我的数据库包含许多空值,如果要显示在网页上,我想消除所有空值。为了消除这些空值,我使用了IS NOT NULL。但它不起作用,或者我在union queries

中使用了正确的方法

这是我的php代码

<?php
session_start();
include('database.php');
$sql = "SELECT * from (
    SELECT * from `class8` where physics8 IS NOT NULL
    UNION 
    SELECT * from `class9`
    UNION
    SELECT * from `class10`
    UNION
    SELECT * from `class11`
    UNION
    SELECT * from `class12`
    ) classes
    WHERE classes.teacher_id = :id";
$stmt = $conn->prepare($sql);
$stmt->bindParam(':id', $_SESSION['teacher_id']);
$result = $stmt->execute();

?>


<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css" integrity="sha384-9aIt2nRpC12Uk9gS9baDl411NQApFmC26EwAOH8WgZl5MYYxFfc+NcPb1dKGj7Sk" crossorigin="anonymous">
    <link href="css/teacherdashboard.css" rel="stylesheet">
    <link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous"/>
    <title>teacher dashboard</title>
    <script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha384-DfXdz2htPH0lsSSs5nCTpuj/zy4C+OGpamoFVy38MVBnE+IbbVYUew+OrCXaRkfj" crossorigin="anonymous"></script>
<script src="https://cdn.jsdelivr.net/npm/popper.js@1.16.0/dist/umd/popper.min.js" integrity="sha384-Q6E9RHvbIyZFJoft+2mJbHaEWldlvI9IOYy5n3zV9zzTtmI3UksdQRVvoxMfooAo" crossorigin="anonymous"></script>
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/js/bootstrap.min.js" integrity="sha384-OgVRvuATP1z7JjHLkuOU7Xw704+h835Lr+6QL9UvYjZE3Ipu6Tp75j7Bh/kR0JKI" crossorigin="anonymous"></script>

</head>
<body>


<nav class="navbar navbarheight navbar-expand-lg navbar-white bg-white">
<a class="navbar-brand" href="teacherdashboard.php"><img  class="logo" height="20%" width="50%" srcset="image/logo1.png" border="0" alt="Null"></a>
  <button class="navbar-toggler" type="button" data-toggle="collapse" data-target="#navbarNavDropdown" aria-controls="navbarNavDropdown" aria-expanded="false" aria-label="Toggle navigation">
    <span class="navbar-toggler-icon"></span>
  </button>
  <div class="collapse navbar-collapse" id="navbarNavDropdown">
    <ul class="navbar-nav">
      <li class="nav-item active">
       <button type="button" onclick="window.location.href='teacherlogout.php';" class="student  btn btn-danger">Logout</button>
      </li>
      </li>
    </ul>
  </div>
</nav>

<div style="margin-top: 10%;" class="container tablediv">
<table class="table table-bordered table-condensed table1 ">
 <thead>
    <tr>
         <th class="col2">physics</th>
         <th class="col2">Chemistry</th>
         <th class="col2">Maths</th>
         <th class="col2">Biology</th>
         <th class="col2">English</th>
    </tr>
 </thead>
 <?php  while ($row = $stmt->fetch(PDO::FETCH_OBJ)) { ?>
    <tr>

         <td> <?php echo $row->physics8 ?></td>
         <td> <?php echo $row->chemistry8 ?></td>
         <td> <?php echo $row->maths8 ?></td>
         <td> <?php echo $row->biology8 ?></td>
         <td> <?php echo $row->english8 ?></td>
    </tr>
 <?php } ?>
 </table>

</div>


<?php include('footer.html') ?>
</body>
</html>

请帮助

0 个答案:

没有答案