问题,下一个先前页pagenition
我得到了一些问题问题,下一个先前页pagenition
注意:未定义的变量:用C pageination:\ XAMPP \ htdocs中\ pagge \ pagenition.php上线28
注意:未定义的变量:上一页在C:\ XAMPP \ htdocs中\ pagge \ pagenition.php上线29
警告:mysql_fetch_array()预计参数1是资源,在布尔C中给出:\ XAMPP \ htdocs中\ pagge \ pagenition.php在线41上我的代码
<?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> ';
}
}
?>
写<?php echo $paginationDisplay; ?>
显示分页没有。
我想知道我的代码的问题:) – 2014-11-25 02:18:30
你的代码是完美的..只是改变$ count_query = mysql_query(“SELECT null FROM product”);到$ count_query = mysql_query(“SELECT * FROM product”); – 2014-11-25 08:23:14
[PHP:“Notice:Undefined variable”和“Notice:Undefined index”]的可能重复(http://stackoverflow.com/questions/4261133/php-notice-undefined-variable-and-notice-undefined-索引) – Justinas 2014-11-24 11:55:55
假设'pagenition.php'存在,位于'C:\ xampp \ htdocs \ pagge \'? – Alex 2014-11-24 11:56:04
在mysql_query()之后在'require(“conn.php”);' – 2014-11-24 11:56:27