Monday, December 7, 2009

Pagination in php

$sql = "SELECT COUNT(*) FROM users";
$result = mysql_query($sql) OR die(mysql_error());
$r = mysql_fetch_row($result);
$numrows = $r[0];

// number of rows to show per page
$rowsperpage = 20;
// find out total pages
$totalpages = ceil($numrows / $rowsperpage);
// get the current page or set a default
if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
// cast var as int
$currentpage = (int) $_GET['currentpage'];
} else {
// default page num
$currentpage = 1;
} // end if

// if current page is greater than total pages...
if ($currentpage > $totalpages) {
// set current page to last page
$currentpage = $totalpages;
} // end if
// if current page is less than first page...
if ($currentpage < currentpage =" 1;" offset =" ($currentpage" term =" $_GET['artist'];" artist =" mysql_real_escape_string($_GET['artist']);" href="http://www.blogger.com/%5C%22admin.php%5C%22">Return to admin section!


";

echo "
Uploads:
";

$sql = "SELECT * FROM users LIMIT $offset, $rowsperpage";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
$result=mysql_query($sql);
while ($list = mysql_fetch_array($result))
{
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";
echo "";


}
echo "";
echo "
idnamegenderdobemailphoneusernamestatusdeleteedit
",$list['id'],"",$list['name'],"", $list['gender'],"",$list['dob'],"",$list['email'],"",$list['phone'],"",$list['username'],"",$list['status'],"", "";
echo "
","\">Deleteuser","", "";
echo "
","\">updatestatus
","
";
echo "

";
$range = 3;

// if not on page 1, don't show back links
if ($currentpage > 1) {
// show << href="http://www.blogger.com/%7B$_SERVER%5B" php_self="" currentpage="1'"><< "; // get previous page num $prevpage = $currentpage - 1; // show < href="http://www.blogger.com/%7B$_SERVER%5B" php_self="" currentpage="$prevpage'">< "; } // end if // loop to show links to range of pages around current page for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) { // if it's a valid page number... if (($x > 0) && ($x <= $totalpages)) { // if we're on current page... if ($x == $currentpage) { // 'highlight' it but don't make a link echo " [$x] ";
// if not current page...
} else {
// make it a link
echo " $x ";
} // end else
} // end if
} // end for

// if not on last page, show forward and last page links
if ($currentpage != $totalpages) {
// get next page
$nextpage = $currentpage + 1;
// echo forward link for next page
echo " NEXT PAGE ";
// echo forward link for lastpage
echo " a href="http://www.blogger.com/%7B$_SERVER%5B" php_self="" currentpage="$totalpages'"> LAST PAGE ";
} // end if
echo "
";

email me to get the code of this coding

rawatsingharun@gmail.com

No comments:

Post a Comment