MySQL中null值問題

來源:互聯網
上載者:User

標籤:code   sql資料庫   value   tab   art   date   alt   and   知識點   

      今天寫答疑係統的時候,寫了這樣一截代碼:

<?phpsession_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中null值問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.