简体   繁体   English

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

[英]Making a column row that is empty from database table not appear in my quiz?

I'm trying to make it so that whenever there are empty cells in columns in my database table, they will not show up in my quiz application. 我试图做到这一点,以便每当数据库表中的列中有空单元格时,它们都不会出现在我的测验应用程序中。

The way that the quiz is built up is that there are groups of four answers that share the same question ID (qid). 测验的构建方式是:由四个答案组成的组共享相同的问题ID(qid)。 When you press the next button you will get to see a set of four new questions and so on. 当您按下下一步按钮时,您将看到一组四个新问题,依此类推。

Right now there are empty spaces in quiz that are given a radiobutton on the side, How do I make it so that empty (answer) cells in my table column in mysql wont show up in my quiz? 现在,测验中有空白空间,侧面有一个单选按钮,如何使测验中的表列中的空白(答案)单元格不会出现在测验中?

My SQL table columns: qid(int), answers(varchar), points(int) 我的SQL表列: qid(int), answers(varchar), points(int)

My code (PHP/HTML) 我的代码(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>

In your SQL you have excluded results where the answer is NULL. 在您的SQL中,您排除了答案为NULL的结果。

Is this how you are storing an empty answer field in your db table; 这就是您在数据库表中存储一个空答案字段的方式; as NULL? 为NULL?

If so you should not get any results for where the field 'answer' is set to NULL. 如果是这样,则在将“答案”字段设置为NULL的情况下,您不会获得任何结果。

Maybe you are storing a string instead of NULL. 也许您存储的是字符串而不是NULL。 You can use this code to see what is returned from an empty answer cell: 您可以使用以下代码查看从空答案单元格返回的内容:

if($row['answer'] == '')
{
    echo "Answer is an empty string.";
}
else if(is_null($row['answer'])){
    echo "Answer is NULL value.";
}
else if($row['answer'] == "NULL")
{
    echo "Answer is the string 'NULL'.";
}

At least now, you will know what the empty answer field in your table are being stored as, and then you can go about removing them from your quiz. 至少现在,您将知道表中的空答案字段存储为什么,然后可以从测验中删除它们。

You could also use your Database Management System (PHPMyAdmin) to check how data is being stored. 您也可以使用数据库管理系统(PHPMyAdmin)来检查数据的存储方式。

Hope this Helps 希望这可以帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM