Wrox Programmer Forums
Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
|
PHP How-To Post your "How do I do this with PHP?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP How-To 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 January 27th, 2006, 05:42 AM
Authorized User
 
Join Date: Jan 2006
Posts: 41
Thanks: 0
Thanked 0 Times in 0 Posts
Default Display results from a database on multiple pages

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 "";
}
echo "</table>";
// close database connection
include("closedb.php");
?></p>

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

Thanks ALL

 
Old January 27th, 2006, 07:58 AM
Friend of Wrox
 
Join Date: Dec 2004
Posts: 154
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Haaaa Previous // Next // Page 1 2 3 4 5
Took me 1 day to work that one out.. it's mathematical more than anything else
1) query your table so you know how many rows you have stored
2) determine how many you want per page ; divide the amount of rows by that number = how many pages
3) carry a variable which tells the program which page you are on and mutiple page by amount of result per page so you know the row number of the 1st row to display
4) use something similar to this:
$query = "SELECT * FROM Table_name WHERE Article_Date BETWEEN '$SearchDate1' AND '$SearchDate2' ORDER BY Article_Date DESC";
  $result = mysql_query($query)
       or die ("Problem encounter ".mysql_error());
  while ($row = mysql_fetch_array($result))
  {
     extract($row);
.
.
.
.
}
Get some coffee you will need it :)





Similar Threads
Thread Thread Starter Forum Replies Last Post
display results carswelljr ASP.NET 2.0 Basics 1 April 19th, 2007 09:46 AM
How do I display search results... aspiretech9 PHP How-To 1 April 26th, 2005 10:12 AM
How do I display search results... aspiretech9 Beginning PHP 1 April 25th, 2005 04:59 PM
Display results from multiple tables Librarian Classic ASP Databases 6 July 6th, 2004 11:28 PM
how do i display results in serperate pages..? kyootepuffy Classic ASP Databases 3 September 10th, 2003 03:18 PM





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