|
-
Apr 9th, 2006, 02:10 AM
#1
Creating pages dynamically
I've been trying to figure out an algorithm to create pages, dynamically.
Like, take my website for example (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?
-
Apr 9th, 2006, 04:17 AM
#2
Re: Creating pages dynamically
Here's my pagination code - hopefully you can make some sense out of this
PHP Code:
$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.
-
Apr 9th, 2006, 06:48 AM
#3
Re: Creating pages dynamically
-
Apr 9th, 2006, 06:51 AM
#4
Re: Creating pages dynamically
And on that note, I must swear that I did not copy Adam's code. :honest:
-
Apr 9th, 2006, 07:17 AM
#5
Re: Creating pages dynamically
 Originally Posted by penagate
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
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|