Solved

Paging results in PHP

Posted on 2007-04-07
1
194 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
1 Comment
 
LVL 20

Accepted Solution

by:
steelseth12 earned 500 total points
ID: 18870941
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
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 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 …

730 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