我有一个带有下面代码的脚本和一个分页,用户可以在其中检查复选框以缩小结果显示一切似乎工作得很好唯一的问题是当用户点击分页中的下一页时结果丢失并显示默认结果。我想我可能需要使用会话来存储查询或语句,但我不确定如何使用它们。如果有人能帮助我或指出我正确的方向,我会非常感激。
<?php
include("config.php");
$start = 0;
$per_page = 10;
if(!isset($_GET['page'])){
$page = 1;
} else
{
$page = $_GET['page'];
}
if($page<=1)
$start = 0;
else
$start = $page * $per_page - $per_page;
$sql="select id,question,correctAnswer,category from math order by id";
$num_rows = mysql_num_rows(mysql_query($sql));
$num_pages = $num_rows / $per_page;
$sql .= " LIMIT $start, $per_page";
$result=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result))
{ ?>
..............
<?php
if($page > 1){
$prev = $page - 1;
$prev = " <a href='?page=$prev'>prev</a> ";
} else {
$prev = "";
}
if($page < $num_pages){
$next = $page + 1;
$next = " <a href='?page=$next'>next</a> ";
}
else
{
$next = "";
}
echo $prev;
echo $next;
?>
以下代码是关于逐个选择复选框值和所有
function selectall()
{
var selectAll = document.forms[0].length;
if(document.forms[0].topcheckbox.checked==true)
{
for(i=1;i<selectAll;i++)
{
document.forms[0].elements[i].checked=true;
}
}
else
{
for(i=1;i<selectAll;i++)
document.forms[0].elements[i].checked=false;
}
}
function goSelect()
{
var select = document.forms[0].length;
var checkboxes=""
for(i=1;i<select;i++)
{
if(document.forms[0].elements[i].checked==true)
checkboxes+= " " + document.forms[0].elements[i].name
}
if(checkboxes.length>0)
{
var con=confirm("You have selected ...........");
if(con)
{
window.location.assign("submit.php?recsno="+checkboxes)
// document.forms[0].submit()
}
}
else
{
alert("No record is selected.")
}
}
答案 0 :(得分:0)
您可以使用PHP Get方法吗?然后在您的JavaScript中接收它。
例如; searchurl.com/results.php?box=1
然后在下一页上检索它。
我相信这应该对您有所帮助,如果您需要更多细节,请务必告诉我。
答案 1 :(得分:0)
这是我的全部代码。
include("config.php");
$start = 0;
$per_page = 10;
if(!isset($_GET['page'])){
$page = 1;
} else{
$page = $_GET['page'];
}
if($page<=1)
$start = 0;
else
$start = $page * $per_page - $per_page;
$sql="select id,question,correctAnswer,category from math order by id";
$num_rows = mysql_num_rows(mysql_query($sql));
$num_pages = $num_rows / $per_page;
$sql .= " LIMIT $start, $per_page";
$result=mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_array($result))
{ ?>
<tr>
<td><input name="<?php echo $row['id']; ?>" type="checkbox" class="check"></td>
<td><center><?php echo htmlspecialchars_decode($row['id'], ENT_QUOTES); ?></center></td>
<td style="padding-left:25px;margin:15px"><?php echo $_SESSION['question']= htmlspecialchars_decode($row['question'], ENT_QUOTES); ?></center></td>
<td><center><?php echo htmlspecialchars_decode($row['correctAnswer'], ENT_QUOTES); ?></center></td>
<td><center><?php echo htmlspecialchars_decode($row['category'], ENT_QUOTES); ?></center></td>
<td><a href="<?php echo "manual_update.php?id=".$row['id']."&mode=update";?>"id="dialog_10">View</a></td>
</tr>
<?php } ?>
<tr>
<td><strong><a href="javascript:goSelect()">Select</a></strong></td>
<td><strong>Sr No </strong></td>
<td><strong>Question </strong></td>
<td><strong>CorrectAnswer </strong></td>
<td><strong>Category </strong></td>
<td><strong>View Details</strong></td>
</tr>
</table>
</td>
</tr>
<tr>
<td>
<?php
if($page > 1){
$prev = $page - 1;
$prev = " <a href='?page=$prev'>prev</a> ";
} else {
$prev = "";
}
if($page < $num_pages){
$next = $page + 1;
$next = " <a href='?page=$next'>next</a> ";
}
else
{
$next = "";
}
echo $prev;
echo $next;
?>