如何显示每一行从数据库在不同的页面在php
how to display each row from database in different page in php?
我有一个代码显示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
在HTML中
第一页末尾:
<a href="?gotopage=2">Next</a>
和
第二页末尾:
<a href="?gotopage=3">Next</a>
和
第三页末尾:
<a href="?dosubmit">Submit</a>
在PHP中if( isset($_GET['gotopage']) && $_GET['gotopage'] == 2 ){
//codes for 2 page
}
分页是一个简单的概念,其中每条记录都被写入显示为页面的a中,并且具有指向具有其他记录数据的其他页面的链接。
参考:简单易用的PHP分页
相关文章:
- 在Javascript中调用PHP数据库变量
- 使用ajax将vales从canvas发送到php数据库
- sql和php数据库条目'落后于'
- 将 php 数据库结果传递给 javascript 数组
- 将 PHP 数据库中的 ID 保存为变量
- .ajax() 没有发布到 PHP 数据库查询
- 将 Javascript 中的复选框总和合并到我的 PHP 数据库表中
- 在按钮单击时用 PHP 数据库中的数据填充组合框,并从数据库中加载选定的值
- 为登录/注册模式实现正确的php数据库访问
- 将php数据库添加到java脚本文件中
- 如何使javascript在php数据库查询后工作
- Cake PHP数据库检查
- AJAX PHP数据库查询不起作用
- 脚本仅返回从 php 数据库中获取的第一个值的 id
- 如何获得php数据库值javascript数组
- PHP数据库-不希望显示javascript代码
- 插入PHP数据库结果到Javascript数组
- 如何在页面点击上运行PHP数据库操作
- 将表单组合中的数据保存到MySQL PHP数据库中
- 使用从PHP /数据库返回的数据创建新表单