Forum Moderators: coopster

Message Too Old, No Replies

Display results from a database on multiple pages

         

osemollie

11:14 am on Jan 27, 2006 (gmt 0)

10+ Year Member



Hi, I am new to PHP and Mysql but am really determined to learn these techniques. I have some script that reads and displays results from the databse onto a page. However, I really wish to limit the number of results that are displayed to 10 per page and then have the next/privious links under the results. With these results, the results under the email field should be hyperlinked so that the person viewing the results should double click on the email link and send the person an email. How can i do that? I have to learn this technique.

The code is:-

<p><?php
$server = "localhost"; // server to connect to.
$database = "dbdbdb"; // the name of the database.
$db_user = "dddd"; // mysql username to access the database with.
$db_pass = "pppp"; // mysql password to access the database with.
$table = "alumni"; // the table that this script will set up and use.
$rows = 20; // the number of table rows to display
//
$link = mysql_connect($server, $db_user, $db_pass)
or die ("Can't connect" .mysql_error());
//
mysql_select_db($database)
or die ("Can't connect" .mysql_error());
//
$sql="SELECT fullnames, company, address, email FROM $table";
// open the table and print a header row.
echo "<table align=center width=500>";
echo "<tr bgcolor='#FAC88B' class='NiceSmallBold' style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'><th>Full Names</th><th>Company</th><th>Address</th><th>E-mail</th></tr>\n";
if ($result=mysql_query($sql)) {
while ($row=mysql_fetch_row($result)) {
echo "<tr bgcolor='#FDE9D0'><td style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'>".$row[0]."</td>";
echo "<td style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'><p align='center'>".$row[1]."</td>";
echo "<td style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'><p align='center'>".$row[2]."</td>";
echo "<td style='font-family: Verdana, Arial, Helvetica, sans-serif; font-size: 11px'><p align='center'>".$row[3]."</td></tr>\n";
}
} else {
echo "<!-- SQL Error ".mysql_error()." -->";
}
echo "</table>";
// close database connection
include("closedb.php");
?></p>

-----------------------------------

Thanks ALL

coopster

6:05 pm on Jan 30, 2006 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



MySQL has a LIMIT [dev.mysql.com] clause that will only return the LIMIT number of rows you specify. It also has an
offset
argument which would allow you to tell it where to start (aids in paging forward and backward).