Solved

Paging results in PHP

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

Revamp Your Training Process

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action.

Question has a verified solution.

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

Build an array called $myWeek which will hold the array elements Today, Yesterday and then builds up the rest of the week by the name of the day going back 1 week.   (CODE) (CODE) Then you just need to pass your date to the function. If i…
This article discusses how to create an extensible mechanism for linked drop downs.
The viewer will learn how to count occurrences of each item in an array.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.

728 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