Solved

Paging results in PHP

Posted on 2007-04-07
1
191 Views
Last Modified: 2013-12-12
I have a simple PHP page that queries the database and then cycles through the recordset and produces a table of records:

<?php
//Database variables
$strConn = "DRIVER={Microsoft Access Driver (*.mdb)}; DBQ=e:\database\db.mdb";

//Access the DB and get the users details
if (!$conn = new COM("ADODB.Connection")) {
      exit("Unable to create an ADODB connection");
}

$conn->open($strConn);

$strSQL = "SELECT tblOrder.OrderID, tblOrder.CustomerID, tblOrder.DateofOrder, tblOrder.DateOrderDespatched, tblProduct.Product, tblOrderLine.Quantity, tblCustomers.FirstNames, tblCustomers.Surname, tblCustomers.Email FROM tblCustomers INNER JOIN (tblProduct INNER JOIN (tblOrder INNER JOIN tblOrderLine ON tblOrder.OrderID = tblOrderLine.OrderID) ON tblProduct.ProductID = tblOrderLine.ProductID) ON tblCustomers.CustomerID = tblOrder.CustomerID ORDER BY tblOrder.DateofOrder DESC";
$rs = $conn->execute($strSQL);      
?>
<table >
                  <tbody>
                  <tr class="tableHead">
                        <td colspan="7">Order List</td>
                  </tr>
                  <?php
                  if ($rs->EOF) {
                  ?>
                  <tr><td align="center" colspan="5"><span style="font-size:12px; font-weight:bold; ">There are no orders awaiting despatch at this time</span></td></tr>
                  <?php
                  }
                  else {
                  ?>
                  <tr class="rowHead">
                        <td align="center">Order #</td>
                        <td>Product</td>
                        <td>Customer Name</td>
                        <td>Order Date</td>
                        <td></td>
                  </tr>
                  <?php
                  }
                  $rowCounter = 0;
                  
                  //Get all the orders for this customer
                  while (!$rs->EOF) {
                  ?>
                        <tr class='odd'>
                              <td align="center"><?php echo $rs->Fields['OrderID']->Value ?></td>
                              <td><?php echo $rs->Fields['Quantity']->Value ?> x <?php echo $rs->Fields['Product']->Value ?></td>
                              <td><?php echo $rs->Fields['FirstNames']->Value . " " . $rs->Fields['Surname']->Value ?></td>
                              <td><?php echo date('jS M Y', $rs->Fields['DateofOrder']->Value) ?></td>
                              <td align="center"><form id="form1" name="form1" method="get" action="vieworder.php">
                                    <input name="OrderID" type="hidden" value="<?php echo $rs->Fields['OrderID']->Value ?>" />
                                    <input type="submit" name="Submit" value="View Order" />
                                </form>
                              </td>
                          </tr>
                          <?php
                        $rs->MoveNext();
                        }
                        ?>
                  </tbody>
      </table>
<?php
//Close the connection
$rs->Close();
$conn->Close();
$rs = null;
$conn = null;
?>

This works great but I want to add paging to table because the number of records is great. I am just starting out with PHP, i have been an ASP for the last 6 years. How can i do the paging, where should i start? Is it easy to code (because i know it can be a pain in the ass in ASP) or are there some simple tutorials out there?
0
Comment
Question by:alex_wareing
1 Comment
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 18870941
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
Developers of all skill levels should learn to use current best practices when developing websites. However many developers, new and old, fall into the trap of using deprecated features because this is what so many tutorials and books tell them to u…
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

790 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question