Created
December 17, 2012 15:54
-
-
Save drifterz28/4319349 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// paging code | |
// Query to count rows. | |
$result = mysql_query("SELECT * FROM Table_Name WHERE Column_Name = '$section'"); | |
$items = 32; // number of items per page. | |
$all = $_GET['a']; //This is the view all param. | |
$num_rows = mysql_num_rows($result); | |
if($all == "all"){ | |
$items = $num_rows; | |
} | |
$nrpage_amount = $num_rows/$items; | |
$page_amount = ceil($num_rows/$items); | |
$page_amount = $page_amount-1; | |
$page = mysql_real_escape_string($_GET['p']); | |
if($page < "1"){ | |
$page = "0"; | |
} | |
$p_num = $items*$page; | |
//end paging code | |
// Query that you would like to SHOW | |
$result = mysql_query("SELECT * FROM Table_Name WHERE Column_Name = '$section' ORDER BY 'name' ASC LIMIT $p_num , $items"); | |
function paging(){ | |
global $num_rows; | |
global $page; | |
global $page_amount; | |
global $section; | |
if($page_amount != "0"){ | |
echo "<div class=paging>"; | |
if($page != "0"){ | |
$prev = $page-1; | |
echo "<a href=\"section.php?q=$section&p=$prev\">Prev</a>"; | |
} | |
for ( $counter = 0; $counter <= $page_amount; $counter += 1) { | |
echo "<a href=\"section.php?q=$section&p=$counter\">"; | |
echo $counter+1; | |
echo "</a>"; | |
} | |
if($page < $page_amount){ | |
$next = $page+1; | |
echo "<a href=\"section.php?q=$section&p=$next\">Next</a>"; | |
} | |
echo "<a href=\"section.php?q=$section&a=all\">View All</a>"; | |
echo "</div>"; | |
} | |
} | |
// call on Pagination with function | |
paging(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment