Home

Forums

Web development

 

 

 

 
     
 
dna88 Web development and Technology Forum
 
Profile   Register   Memberlist   Usergroups   FAQ   Search  Log in
Multipage Navigation with PHP

 
Post new topic   Reply to topic    dna88 Forum Index -> Web scripting language Discussion Forum
Author Message
cloudconstructor
Beginner User
Beginner User


Joined: 29 Apr 2004
Posts: 14

Post Post subject: Multipage Navigation with PHP Reply with quote

Hi Guys,

I need help on multipage navigation in php. I would like to retrieve resultset from the mysql and display 20 results per page. The script will automatically generate links to rest of the results. Anyone, any clue?
Tue May 04, 04 12:15 pm
Back to top
cloudconstructor View user's profile Send private message
quantum
Site Admin
Site Admin


Joined: 07 Mar 2004
Posts: 1048
Location: Dhaka, Bangladesh

Post Post subject: Reply with quote

Nobody seems to answer!!

Here's one way I found:
Firstly, decide if you are going to query the database once or multiple times as needed. The best idea is to query once and cache everything (should only be strings anyway - try use a session variable) - unless your cache is slow (see *). With minimal load (<20 users at once), it's not much of an issue.

With the array from your query, take the first n results and list them. Save the array in $_SESSION (*). Now for your row of HTML links, you are going to pull data from that array in groups of n. All you need to do is pass a variable ($offset) with each link. At the top of the page, if $offset equals anything above n, proceed with pulling from the array the next n elements (with a loop) past the value of $offset from the array and print them. For the link titled "2", pass $offset=2*n, for "3", $offset=3*n.

*$_SESSION is known to be slow because it writes to the server drive. You can use virtual drives (in RAM) or a RAID array to lessen the problem. Others simply place the data in MySQL (perhaps a temporary table).

Consider just querying the database again instead of using $_SESSION. In this case, you could use $offset in your SQL query (after checking $offset to deter tampering) or simply query everything again and use $offset to select the block of current block of results. Either way, every page you make a new query and select your results based on $offset.

This article appears to present a similar solution.
[http://www.phpbuilder.com/columns/rod20000221.php3]
_________________

Dust fills my eyes / Clouds roll by / and I roll with them / Centuries cry / Orders fly / and I fall again
Afford best design, implement best solution. Outsource your web design.
Tue Jun 01, 04 9:05 pm
Back to top
quantum View user's profile Send private message Visit poster's website AIM Address
hasnut
Expert User
Expert User


Joined: 28 Aug 2004
Posts: 201

Post Post subject: Re: Multipage Navigation with PHP Reply with quote

cloudconstructor wrote:
Hi Guys,

I need help on multipage navigation in php. I would like to retrieve resultset from the mysql and display 20 results per page. The script will automatically generate links to rest of the results. Anyone, any clue?


Search google with the below keyword
Code:
php database paging


here are some links
[http://www.webdevtips.com/webdevtips/php/paging.php]
[http://www.sitepoint.com/article/php-paging-result-sets]
the last one is using OOP PHP code
_________________
Sarder Hasnut
MCSD, CIW A

Need Low Cost Prefessional Hosting Contact me
Mon Aug 30, 04 12:30 pm
Back to top
hasnut View user's profile Send private message Visit poster's website MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    dna88 Forum Index -> Web scripting language Discussion Forum All times are GMT - 7 Hours
Page 1 of 1

 

Partners and Resources

Bangladesh hosting company

Bangladesh web design

Driven by phpBB © phpBB Group