就像标题中所说的,我的分页仅出现在首页上。
此查询从用户输入中选择总行数,然后选择他们想要的类型记录。
我想要它做的是获取记录,然后在每个页面上显示它们,但是似乎每次下一次命中它都会再次运行查询并获得一个新值。然后分页按钮(“上一个/下一个”)消失。
我一次在本地运行它就可以了。当我下一个命中时,它转到pagination.php?pn = 2,但随后出现错误
PHP注意:未定义的索引:在第5行计数 PHP注意:未定义的索引:第6行的主题 PHP警告:join():invaldd参数(由于上述通知,我在猜测) PHP警告:mysqli_fetch_row()期望参数1为mysqli_result,给定为boolen(同样可能是由于第5行和第6行,并且得到了错误的值)
这是我的代码。
<?php
include ("link.php");
$limitValue = $_POST['count'];
$type = $_POST['topic'];
$qType = join("','", $type);
$query = mysqli_query($link,"SELECT count(question_id)
FROM questions
WHERE questionType IN ('$qType')
LIMIT $limitValue" );
$row = mysqli_fetch_row($query);
// Assign the value of $row[0] (the results of our query, we need the square brackets for this to work) to $rows
$rows = $row[0];
$page_rows = 1;
$last = ceil($rows/$page_rows);
if($last <1){
$last = 1;
}
$pagenum = 1;
if(isset($_GET['pn'])){
$pagenum = preg_replace('#[^0-9]#', '', $_GET['pn']);
}
if ($pagenum < 1) {
$pagenum = 1;
}
else if ($pagenum > $last) {
$pagenum = $last;
}
$limit = 'LIMIT ' .($pagenum - 1) * $page_rows .',' .$page_rows;
$sql = "SELECT question_id, questionType, question, answerA, answerB, answerC, answerD
FROM questions
WHERE questionType IN ('$qType')
ORDER BY RAND()
$limit";
$result = mysqli_query($link, $sql);
$paginationCtrls = '';
if($last != 1){
if ($pagenum > 1) {
$previous = $pagenum - 1;
$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$previous.'" class="btn btn-default">Previous</a> ';
for($i = $pagenum-4; $i < $pagenum; $i++){
if($i > 0){
$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'" class="btn btn-default">'.$i.'</a> ';
}
}
}
$paginationCtrls .= ''.$pagenum.' ';
for($i = $pagenum+1; $i <= $last; $i++){
$paginationCtrls .= '<a href="'.$_SERVER['PHP_SELF'].'?pn='.$i.'" class="btn btn-default">'.$i.'</a> ';
if($i >= $pagenum+4){
break;
}
}
if ($pagenum != $last) {
$next = $pagenum + 1;
$paginationCtrls .= ' <a href="'.$_SERVER['PHP_SELF'].'?pn='.$next.'" class="btn btn-default">Next</a> ';
}
}
while ($row = mysqli_fetch_array($result)) {
echo "QID: " . $row["question_id"]. "<br>";
"Question Type: " . $row["questionType"]. "<br><br>" ;
"Question: " . $row["question"]. "<br><br><br>";
echo "<input type = 'Radio' Name = 'Answer[]' value ='A' > A. <br>";
echo "<input type = 'Radio' Name = 'Answer[]' value ='B' > B. <br>";
echo "<input type = 'Radio' Name = 'Answer[]' value ='C' > C. <br>";
echo "<input type = 'Radio' Name = 'Answer[]' value ='D' > D. <br><br>";
echo "<input name='submit' type='submit' value='Submit'><br><br><hr>";
echo $paginationCtrls;
}
?>