有没有一种方法可以从db结果中按1显示/隐藏div / form 1?

时间:2019-02-15 11:05:00

标签: javascript php jquery mysqli

我已将数据库中的所有问题随机列出到一个页面中,我想隐藏所有其他div并以1的比例显示它们。

我尝试在查询中使用LIMIT 1,但在处理完该问题后,该问题将反复显示。

<?php
if (mysqli_connect_errno()) {
echo "Failed to connect: " . mysqli_connect_error();
}
$sql = "SELECT * FROM tbl_questions ORDER BY RAND();";
$result = mysqli_query($conn, $sql);
$questionCount = 1;

while($row = mysqli_fetch_assoc($result)) {
$id = $row['id'];
$question = $row['question'];
$choice1 = $row['choice1'];
$choice2 = $row['choice2'];
$choice3 = $row['choice3'];
$choice4 = $row['choice4'];
$answer = $row['answer'];

echo "<div id='d$id'>";
echo "<h4>" . $questionCount++ . ". ". $question . "</h4>";
echo "<input type='radio' id='c1' name='c$id' value='1' checked />" . " 
<label style='font-weight: normal' for='c1'>" . $choice1 . "</label><br/>";
echo "<input type='radio' id='c2' name='c$id' value='2' />" . "<label 
style='font-weight: normal' for='c2'>" . $choice2 . "</label><br/>";
echo "<input type='radio' id='c3' name='c$id' value='3' />" . "<label 
style='font-weight: normal' for='c3'>" . $choice3 . "</label><br/>";
echo "<input type='radio' id='c4' name='c$id' value='4' />" . "<label 
style='font-weight: normal' for='c4'>" . $choice4 . "</label><br/>";
echo "<input type='submit' value='Submit' />";
echo "</div>";
}

1 个答案:

答案 0 :(得分:0)

您应该在数据库中放置一个新列,其名称应类似于“ showhide”,默认情况下应在查询中放置值“ show”

$sql = "SELECT * FROM tbl_questions WHERE `showhide`='show' LIMIT 1";

在单击提交按钮时,更新数据库中具有“隐藏”值的值,因此在下一次加载时,提交的行将不会出现。