Computing.Net > Forums > Web Development > PHP Multipage Navigation

PHP Multipage Navigation

Reply to Message Icon

Original Message
Name: quantumcloud
Date: May 11, 2004 at 14:50:24 Pacific
Subject: PHP Multipage Navigation
OS: Unix
CPU/Ram: Intel
Comment:

Hi,

Can anyone show me an example of how to write a script in php to show multipage navigation links like 1, 2, 3,...last. Script will retrieve result from the database and display a report by breaking it apart into multiple pages as necessary.

An effective forum for serious programmers.
http://www.quantumcloud.com/forum/


Report Offensive Message For Removal

Response Number 1
Name: anonproxy
Date: May 11, 2004 at 18:02:38 Pacific
Subject: PHP Multipage Navigation
Reply: (edit)

Here's one way:

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.


Report Offensive Follow Up For Removal

Response Number 2
Name: quantumcloud
Date: May 12, 2004 at 10:54:11 Pacific
Subject: PHP Multipage Navigation
Reply: (edit)

That was very helpful indeed. Though I need a few days to test it through. But now I got an idea. Thanks, I really appreciate this.

An effective forum for serious programmers.
http://www.quantumcloud.com/forum/


Report Offensive Follow Up For Removal







Use following form to reply to current message:

   Name: From My Computing.Net Settings
 E-Mail: From My Computing.Net Settings

Subject: PHP Multipage Navigation

Comments:

 


  Homepage URL (*): 
Homepage Title (*): 
         Image URL: 
 
Data Recovery Software