Advertisement
tjromano

List Clients

Aug 30th, 2012
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.28 KB | None | 0 0
  1. <?php
  2. session_cache_limiter();
  3. session_start();
  4.      
  5. require('config.php');
  6. require('functions.php');
  7.      
  8. //check for administrative rights
  9. if (allow_access(Administrators) != "yes")
  10. {
  11.      include ('no_access.html');
  12.      exit;
  13. }
  14.  
  15. //counts rows in table
  16. $sql = "SELECT COUNT(*) FROM clients";
  17. $result = mysql_query($sql, $conn) or die(mysql_error());
  18. echo mysql_error();
  19. $r = mysql_fetch_row($result);
  20. $numrows = $r[0];
  21.  
  22. //rows per page
  23. $rowsperpage = 15;
  24.  
  25. // find out total pages
  26. $totalpages = ceil($numrows / $rowsperpage);
  27.  
  28. // get the current page or set a default
  29. if (isset($_GET['currentpage']) && is_numeric($_GET['currentpage'])) {
  30.    // cast var as int
  31.    $currentpage = (int) $_GET['currentpage'];
  32. } else {
  33.    // default page num
  34.    $currentpage = 1;
  35. } // end if
  36.  
  37. // if current page is greater than total pages...
  38. if ($currentpage > $totalpages) {
  39.    // set current page to last page
  40.    $currentpage = $totalpages;
  41. } // end if
  42. // if current page is less than first page...
  43. if ($currentpage < 1) {
  44.    // set current page to first page
  45.    $currentpage = 1;
  46. } // end if
  47.  
  48. // the offset of the list, based on current page
  49. $offset = ($currentpage - 1) * $rowsperpage;
  50.  
  51. $sql = "Select * FROM `clients` WHERE cl_active = '1' ORDER BY cl_ln LIMIT $offset, $rowsperpage";
  52. $result = mysql_query($sql, $conn) or die(mysql_error());
  53.  
  54. $title="List Clients";
  55. include 'ctts_admin_header.php';    
  56.  
  57. ?>
  58.  
  59. <div id="content">
  60. <h2>Clients List</h2>
  61. <table border="1" cellspacing="2" cellpadding="2">
  62. <tr>
  63. <td><font face="Arial, Helvetica, sans-serif">Client Name</font></td>
  64. <td><font face="Arial, Helvetica, sans-serif">Last Name</font></td>
  65. <td><font face="Arial, Helvetica, sans-serif">Grade</font></td>
  66. <td><font face="Arial, Helvetica, sans-serif">Address</font></td>
  67. <td><font face="Arial, Helvetica, sans-serif">City</font></td>
  68. <td><font face="Arial, Helvetica, sans-serif">State</font></td>
  69. <td><font face="Arial, Helvetica, sans-serif">Zip Code</font></td>
  70. <td><font face="Arial, Helvetica, sans-serif">Resides With</font></td>
  71. </tr>
  72.         <?php
  73.         // range of num links to show
  74. $range = 3;
  75.  
  76. // if not on page 1, don't show back links
  77. if ($currentpage > 1) {
  78.    // show << link to go back to page 1
  79.    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=1'><<</a> ";
  80.    // get previous page num
  81.    $prevpage = $currentpage - 1;
  82.    // show < link to go back to 1 page
  83.    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$prevpage'><</a> ";
  84. } // end if
  85.  
  86. // loop to show links to range of pages around current page
  87. for ($x = ($currentpage - $range); $x < (($currentpage + $range) + 1); $x++) {
  88.    // if it's a valid page number...
  89.    if (($x > 0) && ($x <= $totalpages)) {
  90.       // if we're on current page...
  91.       if ($x == $currentpage) {
  92.          // 'highlight' it but don't make a link
  93.          echo " [<b>$x</b>] ";
  94.       // if not current page...
  95.       } else {
  96.          // make it a link
  97.          echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$x'>$x</a> ";
  98.       } // end else
  99.    } // end if
  100. } // end for
  101.                  
  102. // if not on last page, show forward and last page links        
  103. if ($currentpage != $totalpages) {
  104.    // get next page
  105.    $nextpage = $currentpage + 1;
  106.     // echo forward link for next page
  107.    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$nextpage'>></a> ";
  108.    // echo forward link for lastpage
  109.    echo " <a href='{$_SERVER['PHP_SELF']}?currentpage=$totalpages'>>></a> ";
  110. } // end if
  111.  
  112.         while ($rows = mysql_fetch_assoc($result)){
  113.            
  114.             $num=count($rows); 
  115.            
  116.                
  117.      ?>        
  118.         <tr>
  119.         <td width="150"><font face="Arial, Helvetica, sans-serif"><a href="details_client.php?id=<?php echo $id_clients;?>"><?php echo $row['cl_fn'];?> <?php echo $row['cl_ln'];?></a></font></td>
  120.         <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['cl_ln'];?></font></td>
  121.         <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['cl_grade'];?></font></td>
  122.         <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['cl_address'];?></font></td>
  123.         <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['cl_city'];?></font></td>
  124.         <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['cl_state'];?></font></td>
  125.         <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['cl_zip'];?></font></td>
  126.         <td><font face="Arial, Helvetica, sans-serif"><?php echo $row['cl_resides_with'];?></font></td>
  127.         <td><font face="Arial, Helvetica, sans-serif"><a href="edit_clients_form.php?id_aides=<?php echo $row['id_auth'];?>">Edit</a></font></td>
  128.         <td><font face="Arial, Helvetica, sans-serif"><a href="add_schedule_form.php?id_clients=<?php echo $row['id_clients'];?>">View Schedule</a></font></td>
  129.         <td><font face="Arial, Helvetica, sans-serif"><a href="view_schedule_form.php?id_clients=<?php echo $row['id_clients'];?>">Add Schedule</a></font></td>
  130.         </tr>
  131.        
  132.         <?php
  133.          
  134.         }
  135.         ?>
  136.         </table>
  137.         <?php
  138.         echo "Total Records:  $num";
  139.         ?>
  140. <form name="add Car" action="add_client_form.php">
  141. <input type="submit" class="button" value="Add A Client"/>
  142. </form>
  143.      
  144.     <!-- end .content --></div>
  145.     <!-- end content-container --></div>
  146. <?php include 'footer.php'; ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement