Board index   FAQ   Search  
Register  Login
Board index php forum :: Database mySQL & php coding

limit per page with Previous / Next Links

Codes here !

Moderators: macek, egami, gesf

limit per page with Previous / Next Links

Postby Fife Club » Tue Oct 22, 2002 6:20 pm

Somebody else made this suggestion for limiting results to 15 per page with previous/next links:

Have a $page variable...


--------------------

if(!isset($page)) { $page = 0; }

$per_page = 15;
$limit = $page * $per_page;

$query = "SELECT * FROM table LIMIT $limit,$per_page";

--------------------


Something like that...For your next link, you pass $page++, for prev, you pass $page--. Need to throw in some extra stuff that checks the limits of the pages, though....

--------------------

echo "<a href='$PHP_SELF?page=" . $page-- . "'>Prev</a>";
echo "<a href='$PHP_SELF?page=" . $page++ . "'>Next</a>";

--------------------


I can't find this person anymore so I'll ask those of you who may understand.

I added this to my exisitng code and the first page works fine. All other pages work fine if you type "?page=3" or such in the url. The problem seems to come from the previous / next links generated at the bottom. The previous link always links to the CURRENT page and the next link always links to the PREVIOUS page.

See it here:
http://www.pstvalumni.com/directory/index3.php

Or here in a more simplified way with all ORDER BY complications removed:
http://www.pstvalumni.com/directory/index4.php

I don't understand how the last two lines were created so can anybody help me fix them, please? Or can somebody give me a better solution altogether?
User avatar
Fife Club
New php-forum User
New php-forum User
 
Posts: 15
Joined: Wed Oct 09, 2002 7:50 pm
Location: Charlotte, NC, USA

Postby Jay » Wed Oct 23, 2002 2:01 am

The last 2 lines should be:
echo "<a href='$PHP_SELF?page=" . ($page-1) . "'>Prev</a>";
echo "<a href='$PHP_SELF?page=" . ($page+1) . "'>Next</a>";

Whoever wrote that script performed multiple functions on the same variable without taking into account that it would change it before the next!
Jay
 

Postby gegeor » Thu Jul 10, 2003 5:27 am

Jay wrote:The last 2 lines should be:
echo "<a href='$PHP_SELF?page=" . ($page-1) . "'>Prev</a>";
echo "<a href='$PHP_SELF?page=" . ($page+1) . "'>Next</a>";

Whoever wrote that script performed multiple functions on the same variable without taking into account that it would change it before the next!


Is there a way to add the ability to show at the page (top of page etc.) in which exactly page the user is at.??

Thanks
gegeor
New php-forum User
New php-forum User
 
Posts: 4
Joined: Thu Jul 10, 2003 5:25 am

Postby daMax » Fri Jul 11, 2003 2:08 am

gegeor wrote:Is there a way to add the ability to show at the page (top of page etc.) in which exactly page the user is at.??

Thanks


Seems to me that all you need to show the exact page the user is in, is the $page variable...or am I thinking to easy now?
daMax
New php-forum User
New php-forum User
 
Posts: 4
Joined: Tue Jul 08, 2003 1:43 am
Location: Den Bosch, the Netherlands


Return to mySQL & php coding

Who is online

Users browsing this forum: Bing [Bot] and 1 guest

Sponsored by Sitebuilder Web hosting and Traduzioni Italiano Rumeno and antispam for cPanel.