Tema: PHP paging problema...
Autorius: exoticdevil
Data: 2010-04-06 23:44:45
Turiu pasidares scriptuka paging, viskas ok veikia,naudoju kituose vietose 
puslapyje,  bet dabar is db lenteles prireike paimti ne visus duomenis, o 
tik kai kuriuos, ir kazko neveikia,tiksliau pusiau veikia, pirma puslapi 
sugeneruoja, o paspaudus ant sekancio nieko nerodo, tarsi isvis paging'o 
nebutu... nesuprantu kur klaida iveliau, su queriu kazkas ne taip 
manau...visa vakara prasedejau, nebelaiko nervai jau, gal kas padesit..
(sorry del netvarkos)

<?php

 $cat = $_GET['cat'];


include ('admin/sqlcon.php');

mysql_select_db("shop");

$rowsPerPage = 5;
$pageNum = 1;

if(isset($_GET['page']))
{
    $pageNum = $_GET['page'];
}

$offset = ($pageNum - 1) * $rowsPerPage;
$query = " SELECT * FROM items WHERE itemsubcat = '$cat' LIMIT $offset, 
$rowsPerPage";
$result = mysql_query($query) or die('Error, query failed');

while($row = mysql_fetch_array($result))
{

    echo $row["itemcode"]. "<br>";


}

$query   = "SELECT COUNT(itemsubcat) AS numrows FROM items WHERE itemsubcat 
= '$cat'";
$result  = mysql_query($query) or die('Error, query failed2');
$row     = mysql_fetch_array($result, MYSQL_ASSOC);
$numrows = $row['numrows'];
$maxPage = ceil($numrows/$rowsPerPage);
$self = $_SERVER['PHP_SELF'];
$nav  = '';

for($page = 1; $page <= $maxPage; $page++)
{
   if ($page == $pageNum)
   {
       $nav .= "[$page]";
   }
   else
   {
       $nav .= " <a href=\"$self?page=$page\">$page</a> ";
   }
}

if ($pageNum > 1)
{
    $page  = $pageNum - 1;
}

if ($pageNum < $maxPage)
{
    $page = $pageNum + 1;
}
echo $nav ;

?>