设为首页 加入收藏

TOP

MySQL中null值问题
2017-10-13 10:44:29 】 浏览:295
Tags:MySQL null 问题

      今天写答疑系统的时候,写了这样一截代码:

<?php
session_start();
$db=mysqli_connect('localhost','root','root','qa');
$tname=$_POST['teacher'];
$q="select schedule,place from time where Tname='$tname' and Sname is null";
$arr=mysqli_query($db,$q);
echo "您选择了". $tname."老师"."<br/>请继续选择时刻:"."<br/>";
?>
<table border="1" cellspacing="0">
    <tr>
        <th>时刻:</th>
        <th>地点:</th>
    </tr>

  <?php
    while ($result = mysqli_fetch_assoc($arr)) {
        ?>
        <tr>
            <td><?php echo $result['schedule']; ?></td>
            <td><?php echo $result['place']; ?></td>
        </tr>
        <?php
    }
 ?>
    </table>
 <form method="post" action="Stime1.php">
     您选择的时间是:<input type="datetime" name="time" />
     您的问题是:<textarea name="question"></textarea>
    <input type="submit" name="sure" value="确定"/>
</form>

 是想选出某个老师没有被选过的时间段,这样的时间段才能显示在页面上让新的同学选择,但是页面上显示什么都没有,但是数据库中是有符合条件的数据项的存在的,然后我先把这个sql语句复制粘贴到数据库中运行,显示的是查询结果为空,然后我上网搜了一下,发现MySQL数据库中有的时候is null是不起作用的,下面是百度到的说法:

   最后,把Sname is null改为了Sname=‘   ’,成功的查出了需要的结果,虽然是一个小的知识点,但是还是记一下,免得以后再为这种小错误浪费时间。


】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇mysql问题记录 下一篇linux下MongoDB客户端shell基本操..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目