PDA

Click to See Complete Forum and Search --> : Creating pages dynamically


Kasracer
Apr 9th, 2006, 02:10 AM
I've been trying to figure out an algorithm to create pages, dynamically.

Like, take my website for example (BinaryIdiot.com (http://www.binaryidiot.com/)). I get all of my news from a database. I'd like to show, let's say 15 postings at a time, per page.

At the bottom I have a link that goes to next page but that only counts back, like 15 (can't remember if it's 15 or 14) and uses that as a start ID.

For some reason I can't wrap my head around doing actual page numbers. How do I do this?

penagate
Apr 9th, 2006, 04:17 AM
Here's my pagination code - hopefully you can make some sense out of this

$page = (!isset($_GET['p'])) ? 1 : (int)$_GET['p'];
$perPage = (!isset($_GET['pp'])) ? 10 : (int)$_GET['pp'];
$order = (!isset($_GET['order'])) ? 'DESC' :
(strtolower($_GET['order']) == 'asc' ? 'ASC' : 'DESC');

$lower = ($page - 1) * $perPage;

$posts = $db->query(
'SELECT * FROM `posts` ORDER BY `date` '.$order.' LIMIT '.$lower.', '.$perPage
);


$_GET['p'] is the page number (default 1) and $_GET['pp'] is how many posts per page (default 10).

$_GET['order'] is ascending/descending.

visualAd
Apr 9th, 2006, 06:48 AM
Also, check here:

http://www.vbforums.com/showthread.php?p=1988751#post1988751

penagate
Apr 9th, 2006, 06:51 AM
And on that note, I must swear that I did not copy Adam's code. :honest:

visualAd
Apr 9th, 2006, 07:17 AM
And on that note, I must swear that I did not copy Adam's code. :honest:
Sure you didn't.




You'll be hearing from my layer :p