Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
|
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old July 19th, 2004, 05:00 AM
Authorized User
 
Join Date: Jul 2004
Posts: 45
Thanks: 0
Thanked 0 Times in 0 Posts
Default next and previous page results

Languages: PHP + MySQL.

After having several large tables which display the results on one large page, how do you get the results to appear like search engines or this forum where you have 10/20 items listed and you have the next and previous result page links??





Michael.
__________________
Michael.
 
Old July 19th, 2004, 05:15 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

You'd probably use querystring values. Something like http://www.mikesserver.co.uk/list.php?start=10

You'd extract the starting point from the URL...
$start = $_GET['start'];

Work out the finish (i'll assume you want them to come ten at a time):

$end = 10 + $start;

Carry out your query using the LIMIT keyword:

$query = "SELECT lots,of,stuff FROM table LIMIT $start, $end";
$result= mysql_query($result) or die ("Argh! I choke. I die. I cough my last, cursing my creator, because he asked me to &quot;$query&quot;"); //<- don't do this on a live server

And put a hyperlink at the bottom of the page, like this:
echo "<a href=\"list.php?start=$end\">Howay! Giz anuther ten!</a>";

You could put in all sorts of traps like this:

if($end > mysql_num_rows($result)){
//Don't output that hyperlink
}

...and:

if($start>=10){
$start = $start -10:
echo "<a href=\"list.php?start=$start\">Wat wes the ten afooa like, marra?</a>";
}

...and so, ad infinitum.

Dan





Similar Threads
Thread Thread Starter Forum Replies Last Post
How to expire previous page johnsonlim026 ASP.NET 1.0 and 1.1 Basics 6 May 22nd, 2009 12:05 PM
Find previous page gandaliter PHP How-To 2 June 7th, 2007 11:55 AM
Previous Page equal's Nothing jamara ASP.NET 2.0 Professional 9 February 14th, 2007 03:46 PM
Page 1-2-3-4 etc.... Next and Previous buttons crmpicco Classic ASP Basics 1 March 18th, 2005 12:00 PM
go back previous page hosefo81 PHP How-To 2 February 11th, 2004 01:50 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.