在我的测验中没有出现从数据库表中清空的列行?

时间:2015-12-30 11:44:18

标签: php html forms mysqli radio-button

我试图这样做,以便每当我的数据库表中的列中有空单元格时,它们就不会显示在我的测验应用程序中。

测验的构建方式是,有四个答案的组可以共享相同的问题ID(qid)。当您按下下一个按钮时,您将看到一组四个新问题,依此类推。

现在测验中有一些空格,旁边有一个单选按钮,如何制作,以便mysql中我的表格栏中的空(答案)单元格不会显示在我的测验中?

我的SQL表格列: qid(int), answers(varchar), points(int)

我的代码(PHP / HTML)

<html>
    <head>
        <meta charset="utf-8">
        <script>
function goBack() {
    window.history.go(-1);
}
</script>
    </head>
    <body>
    <?php
    $localhost = "localhost";
    $username = "root";
    $password = "";
    $connect = mysqli_connect($localhost, $username, $password) or die ("Kunde inte koppla");
    mysqli_select_db($connect, 'wildfire');

    $qid = 1; 
    if(count($_POST) > 0){ 
    $qid = intval($_POST['qid'])+1; 
    }
    ?>  
            <form method="post" action="">
                <input type="hidden" name="qid" value="<?=$qid?>">
                <?php
                    $sql1 = mysqli_query($connect,"SELECT * FROM question where answer IS NOT NULL && qid =".intval($qid));
                    while($row1=mysqli_fetch_assoc($sql1)){
                    ?>
                    <input type='radio' name='answer1' value="<?php echo $row1['Point'];?>"><?php echo $row1['answer'];?><br>
                    <?php
                    }
                ?>
                    <button type="button" onclick="history.back();">Tillbaka</button>
                <input type='submit' name='forward' value='Nästa'>

            </form>
        </body>

    </html>

1 个答案:

答案 0 :(得分:1)

在SQL中,您排除了答案为NULL的结果。

这是你在db表中存储空答案字段的方式;为NULL?

如果是这样,你不应该得到字段'answer'设置为NULL的任何结果。

也许您存储的是字符串而不是NULL。您可以使用此代码查看从空答案单元格返回的内容:

Add new stock

至少现在,你会知道你的表中的空答案字段被存储为什么,然后你可以从你的测验中删除它们。

您还可以使用数据库管理系统(PHPMyAdmin)来检查数据的存储方式。

希望这有助于