gpt4 book ai didi

php - 如何在php的不同页面中显示数据库中的每一行?

转载 作者:行者123 更新时间:2023-11-30 05:47:33 25 4
gpt4 key购买 nike

我有一个代码可以显示数据库中的 3 个问题和多个答案供用户选择。选择答案后,用户将点击提交按钮。它工作正常。

当前代码:

<?php

$today=date("Y-m-d");

echo "<form method='post' id='submit' action='checkresult.php' dir='rtl'>";
$sql="SELECT * FROM cquestions where showdate='$today' limit 3";
$result=mysql_query($sql);


while ($row = mysql_fetch_array($result)) {
echo "<p>" . $row['cqtext'] . "</p>";
$sql2="SELECT * FROM canswers where cqid=".$row['cqid'];
$result2=mysql_query($sql2);
while($row2=mysql_fetch_assoc($result2))
{
echo "<input type='radio' name='".$row['cqid']."' value='".$row2['cqans']."' />".$row2['aatext'];
}
}


$tomorrow= date("Y-m-d", strtotime("tomorrow"));
$sql4="SELECT * FROM qupdate";
$result4=mysql_query($sql4);
$last_update=mysql_result($result4,"last_update");
if($last_update==$today)
{
$cqid=mysql_result($result,"cqid");
$update1="update cquestions set showdate='$tomorrow' where showdate='0000-00-00' and cqid!='$cqid' order by cqid limit 3";
mysql_query($update1);
$update2="update qupdate set last_update='$tomorrow'";
mysql_query($update2);
$sql3="SELECT * FROM qupdate";
$result3=mysql_query($sql3);
$last_update=mysql_result($result3,"last_update");
}

echo"<br>";
echo"<br>";
echo"<input type='submit' id='submit' name='submit' value='Submit Answers' />";
echo "</form>" ;
?>

以上代码的输出

question1
ans1, ans2, ans3, ans4

question2
ans1, ans2, ans3, ans4

question3
ans1, ans2, ans3, ans4

SUBMIT

我想做一些改变。我想让它在第一页显示第一个问题,然后用户点击下一步,然后它必须转到第二个问题,然后是第三个问题,最后提交按钮。

期待输出

page1
Question 1
ans1, ans2, ans3, ans4

Next

after choosing the ans user clicks next
page2
question 2
ans1, ans2, ans3, ans4

Next

page3
question 3
ans1, ans2, ans3, ans4

SUBMIT Button.

怎么做?

最佳答案

你可以用 jquery show/hide or fadeIn/fadeOut 来做到这一点

<form>
<div id="question1" class="questions">
//php question and its answers in radio
<a href="javascript:void(0)" onclick="getnext('question2')"></a>
</div>
<div id="question2" class="questions" style="display:none">
//php question and its answers in radio
<a href="javascript:void(0)" onclick="getnext('question3')"></a>
</div>
<div id="question3" class="questions" style="display:none">
//php question and its answers in radio
<input type="submit"/>
</div>


<script type="text/javascript">
function getnext(id){
//for fade effect
$(".questions").fadeOut("fast");
$("#"+id).fadeIn("slow");
//for show/hide
$(".questions").hide();
$("#"+id).show();
}
</script>

确保你已经包含了jquery

关于php - 如何在php的不同页面中显示数据库中的每一行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17131973/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com