Don't like ads? PRO users don't see any ads ;-)
Guest

Untitled

By: a guest on Apr 28th, 2012  |  syntax: None  |  size: 2.82 KB  |  hits: 13  |  expires: Never
download  |  raw  |  embed  |  report abuse  |  print
Text below is selected. Please press Ctrl+C to copy to your clipboard. (⌘+C on Mac)
  1. pagination/ PHPSense Pagination Class
  2. <?php
  3.  
  4. echo '<h1>Customers:</h1>';
  5. include ('ps_pagination.php');
  6.  
  7. //Make the Database Connection
  8.     $conn = mysqli_connect ("db", "username", "password", "dbname") OR die ('Could not connect to MySQL:' .mysqli_connect_error() );
  9.  
  10.  
  11.  
  12. $sql = "SELECT CONCAT(left(FirstName,1),left(MiddleName,1),LastName) AS UserName,
  13.       CONCAT(LastName, ', ', FirstName, ' ', MiddleName) AS Name,
  14.       (NewCustomerID) AS customerid,
  15.       (OldCustomerID) AS oldcustomerid,
  16.       (zlu_birthmonth.Description) AS birthmonth,
  17.       (zlu_cars.Description) AS cartype,
  18.       (zlu_carcolor.Description) AS carcolor,    
  19.       (zlu_computers.Description) AS computer,
  20.       (zlu_race.Description) AS race,
  21.       (zlu_residence.Description) AS residence,
  22.       (IsLaptop) AS IsLaptop,
  23.         CASE IsLaptop
  24.             WHEN '1' THEN 'Yes'
  25.             WHEN '0' THEN 'No'
  26.         END AS laptop
  27.  
  28.   FROM customer
  29.     INNER JOIN zlu_cars ON(customer.CarID = zlu_cars.CarID)
  30.     INNER JOIN zlu_birthmonth ON(customer.BirthMonthID = zlu_birthmonth.BirthMonthID)
  31.     INNER JOIN zlu_carcolor ON (customer.CarColorID = zlu_carcolor.CarColorID)
  32.     INNER JOIN zlu_computers ON (customer.ComputerID = zlu_computers.ComputerID)
  33.     INNER JOIN zlu_race ON(customer.RaceID = zlu_race.RaceID)
  34.     INNER JOIN zlu_residence ON(customer.ResidenceID = zlu_residence.ResidenceID)
  35.     order by NewCustomerID ";
  36.  
  37. $pager = new PS_Pagination($conn, $sql,10,7);
  38. $rs=$pager->paginate();
  39.     echo '<table  border="1" bgcolor="#eeeeee">
  40.               <tr>
  41.                 <th>Customer ID</th>
  42.                 <th>Old Customer ID</th>
  43.                 <th>Customer Name</th>
  44.                 <th>UserName</th>
  45.                 <th>Car</th>
  46.                 <th>Car Color</th>
  47.                 <th>Birth Month</th>
  48.                 <th>Computer Brand</th>
  49.                 <th>Laptop</th>
  50.                 <th>Race</th>
  51.                 <th>Residence</th>
  52.             </tr>';
  53.  
  54.     $bg = '#eeeeee'; // set initial back ground color
  55.     $r = @mysqli_query($conn, $sql); if(!$r){die(mysqli_error($conn));}
  56.     while ($row = mysqli_fetch_array($r, MYSQLI_ASSOC)) {
  57.         $bg = ($bg =='#eeeeee' ? '#ffffff' : '#eeeeee'); // switch the background color.
  58.  
  59.     echo '<tr bgcolor="' . $bg . '">
  60.                 <td>' . $row['customerid']. '</td>
  61.                 <td>' . $row['oldcustomerid']. '</td>
  62.                 <td>' . $row['Name'].'</td>
  63.                 <td>' . $row['UserName'].'</td>
  64.                 <td>' . $row['cartype'].'</td>
  65.                 <td>' . $row['carcolor'].'</td>
  66.                 <td>' . $row['birthmonth'].'</td>
  67.                 <td>' . $row['computer'].'</td>
  68.                 <td>' . $row['laptop'].'</td>
  69.                 <td>' . $row['race'].'</td>
  70.                 <td>' . $row['residence'].'</td>
  71.  
  72.  
  73.                 </tr>'; }
  74.  
  75.         echo '</table>';
  76. echo $pager->renderFullNav();
  77.  
  78.  
  79.  
  80.  
  81. ?>