Php 页面启动中的下一个上一页出现问题
我遇到了一些问题 注意:未定义的变量:第28行C:\xampp\htdocs\pagge\pagenition.php中的分页 注意:第29行的C:\xampp\htdocs\pagge\pagenition.php中的未定义变量:prev 警告:mysql_fetch_array()希望参数1是资源,布尔值在第41行的C:\xampp\htdocs\pagge\pagenition.php中给出 这是我的密码Php 页面启动中的下一个上一页出现问题,php,Php,我遇到了一些问题 注意:未定义的变量:第28行C:\xampp\htdocs\pagge\pagenition.php中的分页 注意:第29行的C:\xampp\htdocs\pagge\pagenition.php中的未定义变量:prev 警告:mysql_fetch_array()希望参数1是资源,布尔值在第41行的C:\xampp\htdocs\pagge\pagenition.php中给出 这是我的密码 <?php require("conn.php"); $count_query
<?php
require("conn.php");
$count_query = mysql_query("SELECT null FROM product");
$count = mysql_num_rows($count_query);
if(isset($_GET['page'])){
$page=preg_replace("#[^0-9]#","",$_GET['page']);
}else{
$page = 1;
}
$perPage = 2;
$lastPage = ceil($count/$perPage);
$limit = "LIMIT". ($page-1)*$perPage .", $perPage";
$query = mysql_query("SELECT P_name FROM product ORDER BY P_id DESC '$limit'");
if($lastPage!=1){
if($page != $lastPage){
$next = $page + 1;
$pageination .= '<a href= "pagenition.php?page='.$next.">NEXT </a>" ;
}
}
if($lastPage!=1){
if($page != $lastPage){
$prev = $page - 1;
$pageination .= '<a href= "pagenition.php?page='.$prev.">Prev </a>" ;
}
}
while($row=mysql_fetch_array($query)){
$output .= $row['P_name'] . "<hr/>";
}
?>
<html>
<body>
<h1> pagenition example </h1>
<?php echo $output ?>
<?php echo $pageination ?>
</body>
</html>
分页的简单代码
<?php
$sql = "select * from tb_name order by id desc";
$result = mysql_query($sql);
$no = mysql_num_rows($result);
if (isset($_GET['page'])) {
$page = preg_replace('#[^0-9]#i', '', $_GET['page']);
} else {
$page = 1;
}
$itemsPerPage = 30;
$lastPage = ceil($no / $itemsPerPage);
if ($page < 1) {
$page = 1;
} else if ($page > $lastPage) {
$page = $lastPage;
}
$centerPages = "";
$sub1 = $page - 1;
$sub2 = $page - 2;
$add1 = $page + 1;
$add2 = $page + 2;
if ($page == 1) {
$centerPages .= ' <span class="pagNumActive">' . $page . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $add1 . '">' . $add1 . '</a> ';
} else if ($page == $lastPage) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $page . '</span> ';
} else if ($page > 2 && $page < ($lastPage - 1)) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $sub2 . '">' . $sub2 . '</a> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $page . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $add1 . '">' . $add1 . '</a> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $add2 . '">' . $add2 . '</a> ';
} else if ($page > 1 && $page < $lastPage) {
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $sub1 . '">' . $sub1 . '</a> ';
$centerPages .= ' <span class="pagNumActive">' . $page . '</span> ';
$centerPages .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $add1 . '">' . $add1 . '</a> ';
}
$limit = 'limit ' .($page - 1) * $itemsPerPage .',' .$itemsPerPage;
$sql2 = mysql_query("select * from tb_name order by id desc $limit");
$paginationDisplay = "";
if ($lastPage != "1"){
$paginationDisplay .= 'Page <strong>' . $page . '</strong> of ' . $lastPage. ' ';
if ($page != 1) {
$previous = $page - 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $previous . '" style="text-decoration:none;"> Previous </a> ';
}
$paginationDisplay .= '<span class="paginationNumbers">' . $centerPages . '</span>';
if ($page != $lastPage) {
$nextPage = $page + 1;
$paginationDisplay .= ' <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $nextPage . '" style="text-decoration:none;"> Next</a> ';
}
}
?>
假设在位置“C:\xampp\htdocs\pagge\”存在“pagenition.php”的可能重复项?添加$pageination=”
afterrequire(“conn.php”)代码>在mysql\u query()之后使用“或死(mysql\u error())”。将有助于检测任何查询错误。还可以打印查询一次,以检查是否获得了所有正确的值。还建议您以后切换到预置语句。您的代码非常完美..只需更改$count_query=mysql_query(“从产品中选择null”);to$count\u query=mysql\u query(“从产品中选择*);