It appears you have not yet registered with DEVPPL. To register please click here... (it's fast, easy and free!)

Forum

Log In Sponsors
Board index Programming PHP and MySQL Forum

Using Next & Prev for 20+ items

Moderator: Malcolm

Using Next & Prev for 20+ items

Postby dflynn on Tue Jan 06, 2009 4:46 am

So I want to test myself to build this part of my site. I've become relatively comfortable with php and mysql and I want to see if I can do this without having code given to me.
I just need a push in the right direction as to where to start.

I am having content displayed from the database and when I reach a certain amount I want to be able to use a system similar to wordpress where when you hit say 10 entries it adds the "older entries" link and displays the next 10 entries and so on.

What would be the best way to start going about this?

I can manage displaying 20 at a time in descending order and can probably figure out displaying Prev and Next links when it hits 20. I jsut don't understand how to get the next page to show the next 20 without coding each page individually... is there an easier way?



(sorry for rambling)
User avatar
dflynn
500+ Club
 
Posts: 860
Joined: Wed Oct 03, 2007 9:06 pm
Location: Guelph, Canada

Re: Using Next & Prev for 20+ items

Postby webmaster on Tue Jan 06, 2009 8:13 am

For the link:
Code: Select all
if(empty($_G.ET['page'])) {
   $page = 2;
} else {
   $page = $_G.ET['page']+1;
}

echo "<a href=\"?page=" . $page . "\">Older Posts</a>";



For SQL:
Code: Select all

if(empty($_G.ET['page'])) {
   $start = 0;
} else {
   $start = $_G.ET['page']*10;
}

$query = "SELECT * FROM ababab ORDER BY added DESC LIMIT " . $start . ",10";
$result = mysql_query($query);

while ($data = @mysql_fetch_array($result)) {

   $a = $data['a'];
   $b = $data['b'];

   echo $a . " - " . $b . "<br />";

}



And change G.ET to GET :)
User avatar
webmaster
Site Admin
 
Posts: 2695
Joined: Tue Aug 17, 2004 1:07 pm
Location: Sweden


Who is online

Users browsing this forum: No registered users and 0 guests