Solved

Paging results in PHP

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

Enterprise Mobility and BYOD For Dummies

Like “For Dummies” books, you can read this in whatever order you choose and learn about mobility and BYOD; and how to put a competitive mobile infrastructure in place. Developed for SMBs and large enterprises alike, you will find helpful use cases, planning, and implementation.

Question has a verified solution.

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

Generating table dynamically is the most common issue faced by php developers.... So it seems there is a need of an article that explains the basic concept of generating tables dynamically. It just requires a basic knowledge of html and little maths…
This article discusses how to create an extensible mechanism for linked drop downs.
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…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

770 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