Question:
Pagination Php codes?
Archie + Gossip girl!
2011-01-05 08:22:42 UTC
hi i need some help on the pagination codes. i've created a really basic one whereby the user can only click "Previous" or " Next " but i'm trying to do something whereby there are page numbers being displayed and the user can click on whichever page they want to view instead of pressing "next " over and over. If you don't understand what i'm saying, check out this website : http://store.fueledbyramen.com/artists/show_by_artist/7

I'm hoping to do what they did on the website where they show maybe the first three pages and the last three pages.. with dots in the middle to represent the middle pages. Below are my codes, I'd appreciate if you can guide me through on how to improve my current codes. Thanks!

// *** Setup pagination.
$sql = "SELECT * FROM public_subscribe";
$result = mysql_query($sql);

if (!$result) {
echo("

Could not get pagination information.");
} else {
$numRecords = mysql_num_rows($result);
$numPages = ceil($numRecords / $numRecsPerPage);

if ($numPages > 1) {
// *** Display pagination controls.
$prevControl = '' ;
$nextControl = '' ;

if($pageNum > 1) {
$prevPage = $pageNum - 1;
$prevControl =
"PREV";}

if ($pageNum < $numPages) {
$nextPage = $pageNum + 1;
$nextControl =
"NEXT";
}

Three answers:
?
2011-01-05 09:33:18 UTC
- Count the entries using a mysql query => $nrecs as a global

- Set a number of entries per page. => $recpp as a global

- Calculate the number of pages => $npages = intval($nrecs / $recpp) +1; as a global

- Write a function to show the entries for that page

function show_page($pageno) // $pageno -> 1 to n

{

global $recpp;

- Get the entries for that page in a query, setting limits

$pageno--; // index starts at 0!

$fst = $pageno * $recpp;

$sql = "select .... limit " . $fst . ", " . $recpp;

...

while (getting record)

display record;

}

Write a function to show the list of pages

function show_links()

{

global $npages;

for ($pageno = 1; $pageno <= $npages; $pageno++)

{

echo ("".$pageno. "");

}

==> 1 - 2 - 3 .. n

- On click on a link, come to your "body"




if (isset ($_GET['pageno']))

show_page($_GET['pageno']);

else

(show entry page)





(Not fully detailed and unchecked, but that is the idea!)
2011-01-07 04:32:46 UTC
Hi, Try a personal development approach. With everything we listen to on our iPod's, the Radio, etc. it's nice to have something that harnesses the natural power of our brain. See what you think.

This source has over 200 different categories of MP3 recordings that enabled my brother and my sister to make changes in their lives and BOY DID THEY NEED IT... 8)

Anyway, maybe it will be of help to you. Friend me on FaceBook if you have an account.



And may circumstance always prevail in your favor!
John O
2011-01-05 08:25:53 UTC
If this is for something like Drupal, there are plug-ins that offer different types of pagination. Alternately, I found about a dozen that would work just by doing a Google search.


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...