Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP How-To
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
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 tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old January 27th, 2006, 05:42 AM
Authorized User
 
Join Date: Jan 2006
Location: , , .
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

Reply With Quote
  #2 (permalink)  
Old January 27th, 2006, 07:58 AM
Friend of Wrox
 
Join Date: Dec 2004
Location: London, London, United Kingdom.
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 :)
Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


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



All times are GMT -4. The time now is 04:25 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.