Re: Paging help needed :-(
| From: | Dobromir Velev | Date: | Thu, 12 Jul 2001 07:19:26 +0000 |
| Subject: | Re: Paging help needed :-( | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-10330@lists.php.net to get a copy of this message | ||
Hi,
First you'll have to modify your query to show only ten rows.
$sql = "SELECT id, email, name, subject, url, image2, comments, dat
FROM users
ORDER BY id DESC LIMIT $start,10";
The $start variable shows the number of the first row to show
The links for the previous and next page will be something like this
<?
if ($start>=10)echo "<a
href='your_page.php3?".($start-10)."'>Previous</a>";
echo "<a href='your_page.php3?".($start+10)."'>Next</a>";
?>
You can play around with this code to allow the users to go directly to a
specific page, not to show the "Next" link when there are no more records to
show, allow users to define how many records to show in a page and etc.
Dobromir Velev
-----Original Message-----
From: chris@planetoxygene.com <chris@planetoxygene.com>
To: php-db@lists.php.net <php-db@lists.php.net>
Date: Thursday, July 12, 2001 7:53 AM
Subject: [PHP-DB] Paging help needed :-(
Hi there Everyone,
I currently have a dedicated Apache server with PHP 4.06, MySQL etc ..
installed and running fine. Below is alittle peice of code that I would
love an answer to:
<?php
$connection = mysql_connect("Localhost","username!!!","password!!!")
or
die("Couldn't make a connection.");
$db = mysql_select_db("planet", $connection)
or die("Couldn't select database.");
$sql = "SELECT id, email, name, subject, url, image2, comments, dat
FROM users
ORDER BY id DESC";
$sql_result = mysql_query($sql,$connection)
or die("Couldn't execute query.");
?>
<?
while ($row = mysql_fetch_array($sql_result)) {
$email = $row["email"];
$name = $row["name"];
$subject = $row["subject"];
$url = $row["url"];
$image2 = $row["image2"];
$comments = $row["comments"];
$dat = $row["dat"];
$comments=nl2br($comments);
include("censorguestbook.php");
$ip = getenv ("REMOTE_ADDR");
?>
then all the HTML and display bits (Example at www.planetoxygene.com in the
guestbook).
<?
}
mysql_free_result($sql_result);
mysql_close($connection);
?>
Now my question is, how do I do paging in PHP? I need to display 10 entries
per page, and be able to go back and forth with them. I'm relatively new to
PHP so I would be really grateful for any advice.
Thanks everyone, I appreciate it.
Chris Payne
www.planetoxygene.com