问题,下一个先前页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> 
+0

[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

+0

假设'pagenition.php'存在,位于'C:\ xampp \ htdocs \ pagge \'? – Alex 2014-11-24 11:56:04

+1

在mysql_query()之后在'require(“conn.php”);' – 2014-11-24 11:56:27

为分页简单的代码...

<?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 .= '&nbsp; <span class="pagNumActive">' . $page . '</span> &nbsp;'; 
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $add1 . '">' . $add1 . '</a> &nbsp;'; 
} else if ($page == $lastPage) { 
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $sub1 . '">' . $sub1 . '</a> &nbsp;'; 
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $page . '</span> &nbsp;'; 
} else if ($page > 2 && $page < ($lastPage - 1)) { 
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $sub2 . '">' . $sub2 . '</a> &nbsp;'; 
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $sub1 . '">' . $sub1 . '</a> &nbsp;'; 
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $page . '</span> &nbsp;'; 
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $add1 . '">' . $add1 . '</a> &nbsp;'; 
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $add2 . '">' . $add2 . '</a> &nbsp;'; 
} else if ($page > 1 && $page < $lastPage) { 
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $sub1 . '">' . $sub1 . '</a> &nbsp;'; 
    $centerPages .= '&nbsp; <span class="pagNumActive">' . $page . '</span> &nbsp;'; 
    $centerPages .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $add1 . '">' . $add1 . '</a> &nbsp;'; 
} 

$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. '&nbsp; &nbsp; &nbsp; '; 

    if ($page != 1) { 
     $previous = $page - 1; 
     $paginationDisplay .= '&nbsp; <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 .= '&nbsp; <a href="' . $_SERVER['PHP_SELF'] . '?page=' . $nextPage . '" style="text-decoration:none;"> Next</a> '; 
    } 
} 
?> 

<?php echo $paginationDisplay; ?>显示分页没有。

+0

我想知道我的代码的问题:) – 2014-11-25 02:18:30

+0

你的代码是完美的..只是改变$ count_query = mysql_query(“SELECT null FROM product”);到$ count_query = mysql_query(“SELECT * FROM product”); – 2014-11-25 08:23:14