Solved

Paging results in PHP

Posted on 2007-04-07
1
183 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

These days socially coordinated efforts have turned into a critical requirement for enterprises.
Since pre-biblical times, humans have sought ways to keep secrets, and share the secrets selectively.  This article explores the ways PHP can be used to hide and encrypt information.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

746 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now