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: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
To: [EMAIL PROTECTED] <[EMAIL PROTECTED]>
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



-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]

Reply via email to