pagination using php with mysql data

Posted by pradeep on Stack Overflow See other posts from Stack Overflow or by pradeep
Published on 2010-06-02T20:02:53Z Indexed on 2010/06/02 20:04 UTC
Read the original article Hit count: 145

Filed under:

i am trying to create a pagination in which there are 5 items at a time depending on the number of items in DB. i wrote this code . but i dono how to go further .its buggy..any better pagination or alteration for this

<?php

$myresult .= "<div class='pagination' >";

if ($pagenum == 1)
{
}
else
{
$pagenum = 1;
$myresult .= "<a href='javascript:newPage(\"".$pagenum."\")'>&nbsp;first&nbsp;</a>";

$myresult .= " ";

$previous = $pagenum-1;
$myresult .= "<a href='javascript:newPage(\"".$previous."\")'> &nbsp;Prev&nbsp;</a>";

if ($pagenum == $last)
{

$previous3 = $pagenum-4;
$myresult .= "<a href='javascript:newPage(\"".$previous3."\")'> &nbsp; $previous3 &nbsp;</a>";

$previous2 = $pagenum-3;
$myresult .= "<a href='javascript:newPage(\"".$previous2."\")'> &nbsp; $previous2 &nbsp;</a>";
}
if ($pagenum > 2)
{
$previous1 = $pagenum-2;
$myresult .= "<a href='javascript:newPage(\"".$previous1."\")'> &nbsp; $previous1 &nbsp;</a>";

}
if ($pagenum > 1)
{

$previous2 = $pagenum-1;
$myresult .= "<a href='javascript:newPage(\"".$previous2."\")'> &nbsp; $previous2 &nbsp;</a>";
$myresult .= " ";

}



}

$myresult .= "<span class=\"disabled\"> $pagenum </span>";



if ($pagenum == $last)
{
}
else {

if($pagenum < $last - 1)
{
$next = $pagenum+1;
$myresult .= "<a href='javascript:newPage(\"".$next."\")'>&nbsp; $next &nbsp;</a>";
}
if($pagenum < $last - 2)
{
$next1 = $pagenum+2;
$myresult .= "<a href='javascript:newPage(\"".$next1."\")'> &nbsp; $next1 &nbsp;</a>";
}
if($pagenum == 1 )
{
$next2 = $pagenum+3;
$myresult .= "<a href='javascript:newPage(\"".$next2."\")'> &nbsp; $next2 &nbsp;</a>";

$next3 = $pagenum+4;
$myresult .= "<a href='javascript:newPage(\"".$next3."\")'> &nbsp; $next3 &nbsp;</a>";
}
if($pagenum == 2 )
{
$next2 = $pagenum+3;
$myresult .= "<a href='javascript:newPage(\"".$next2."\")'> &nbsp; $next2 &nbsp;</a>";
}
$next = $pagenum+1;
$myresult .= "<a href='javascript:newPage(\"".$next."\")'>&nbsp;Next&nbsp;</a>";


$myresult .= "<a href='javascript:newPage(\"".$last."\")'>&nbsp;Last</a>";

}
$myresult .= "</div>";
$myresult .= "</br>";
?>

© Stack Overflow or respective owner

Related posts about php