Guest User

PHP MYSQL AJAX

a guest
Apr 3rd, 2013
245
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
HTML 5.72 KB | None | 0 0
  1. <?php
  2. session_start(); // NEVER forget this!
  3. ?>
  4. <!DOCTYPE html>
  5. <html>
  6.     <head><script type="text/javascript">
  7. window.onload = function(){
  8.   var text_input = document.getElementById ('id');
  9.   text_input.focus ();
  10.   text_input.select ();
  11. }
  12. </script>
  13. <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
  14. <script type="text/javascript">
  15. $(document).ready(function() {
  16.  
  17.     $("#license_no_update").submit(function() {
  18.  
  19.         var license_no_update = $(this).serialize();
  20.  
  21.         $.post('license_update.php', license_no_update, function(data) {
  22.  
  23.                 // We not pop the output inside the #output DIV.
  24.                 $("#output").html(data);
  25.  
  26.         });
  27.  
  28.         return false;
  29.     });
  30.  
  31. });
  32. </script>
  33.  
  34.      <link rel="stylesheet" type="text/css" href="style.css">
  35.         <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
  36.         <title></title>
  37.      </head>
  38.     <body><div class="return_to_main"><a href="index.php"><img src="images/main_page.jpg" /></a></div>
  39.     <center>Search for Student - Scan Barcode:<form action="view_student.php" mathod="POST">
  40.             <input type="text" name="id" id="id" size="20" autofocus />
  41.         </form><?php
  42. //connect to DB
  43. $conn = mysql_connect('details hidden. ');
  44. mysql_select_db("web77-fsma", $conn) or die(mysql_error());
  45.  
  46. //find total number of students.
  47. $beginners = mysql_query("SELECT * FROM students WHERE class = 'Child Beginners' AND status <> 'Suspended'");
  48. $intermediate = mysql_query("SELECT * FROM students WHERE class = 'Intermediate' AND status <> 'Suspended'");
  49. $advanced = mysql_query("SELECT * FROM students WHERE class = 'Advanced' AND status <> 'Suspended'");
  50. $adults = mysql_query("SELECT * FROM students WHERE class = 'Adults' AND status <> 'Suspended'");
  51. $lm = mysql_query("SELECT * FROM students WHERE class = 'Little Monsters' AND status <> 'Suspended'");
  52. $total = mysql_query("SELECT * FROM students WHERE status <> 'Suspended'");
  53. $suspended = mysql_query("SELECT * FROM students WHERE status = 'Suspended'");
  54.  
  55. //display totals
  56. echo '<b>Total Students: </b>'.mysql_num_rows($total) .' &brvbar; <b>Total Suspended:</b> '.mysql_num_rows($suspended).'<br />';
  57. echo '<b>Little Monsters:</b> '.mysql_num_rows($lm).' &brvbar; <b>Child Beginners:</b> ' . mysql_num_rows($beginners) .' &brvbar; <b>Intermediate:</b> ' .mysql_num_rows($intermediate).'  &brvbar; <b> Advanced:</b> ' . mysql_num_rows($advanced).' &brvbar; <b> Adults: </b>' .mysql_num_rows($adults).' <br />';
  58. ?><table >
  59.     <tbody>
  60.         <tr class="header">
  61.             <td><b>Name</b></td>
  62.             <td><b>DOB</b></td>
  63.             <td><b><center>Age</center></b></td>
  64.             <td><b>Grade</b></td>
  65.            
  66.             <td><b><center>Last Attended</center></b></td>
  67.                         <td><b><center>Venue</center></b></td>
  68.                         <td><b>Class</b></td>
  69.                         <td><b>Date Joined</b></td>
  70.                         <td><b>License No.</b></td>
  71.                         <td><b>Status</b></td>
  72.         </tr>
  73.     <?php
  74.      // find_in_set(Class,'Active,2 Week Trial,4 Week Trial,Suspended,Cancelled),
  75. $sql = mysql_query("SELECT * from students ORDER BY name");
  76. while($row = mysql_fetch_array($sql))
  77. {
  78.       $student_id = $row['student_id'];
  79.        ?>   <tr class="<?php echo $row['status']; ?>">
  80.             <td><a href="view_student.php?id=<?php echo $row['student_id']; ?>"><?php echo $row['name']; ?></a></td>
  81.             <td><?php $dob = date('d M Y', strtotime($row['dob'])); echo $dob; ?></td>
  82.             <td><center><?php $dob = $row['dob'];
  83. $today = date('d-m-Y');
  84.  
  85. $diff = abs(strtotime($dob) - strtotime($today));
  86.  
  87. $years = floor($diff / (365*60*60*24));
  88.  
  89. $months = floor(($diff - $years * 365*60*60*24) / (30*60*60*24));
  90.  
  91. $days = floor(($diff - $years * 365*60*60*24 - $months*30*60*60*24)/ (60*60*24));
  92.  
  93. //printf("%d years \n", $years, $months, $days);
  94.  
  95.  
  96. echo $years.'yrs';
  97. ?></center>
  98. </td>
  99.             <td><?php  //find current grade
  100.                       $sql2 = mysql_query("SELECT * FROM gradings WHERE (student_id = ".$student_id.")ORDER BY ID DESC  LIMIT 1")or die(mysql_error());
  101.      if($row2 = mysql_fetch_array($sql2)){ echo $row2['grade'];
  102. }else{  echo 'N/A'; }?></td>
  103.            
  104.             <td><center><?php  //find last attended date.
  105.                       $sql2 = mysql_query("SELECT * FROM attendance WHERE (student_id = ".$student_id.")ORDER BY date DESC LIMIT 1")or die(mysql_error());
  106.      if($row2 = mysql_fetch_array($sql2)){ echo $row2['date'];
  107. }else{  echo 'N/A'; }?></center></td>
  108.                         <td><center><?php echo $row['venue']; ?></center></td>
  109.                         <td><?php echo $row['Class']; ?></td>
  110.                         <td><?php $date_joined = date('d M Y', strtotime($row['date_joined'])); echo $date_joined; ?></td>
  111.                         <td><?php // check if license number exists.
  112.                        if($row['license_no'] == '')
  113.                        {
  114.                            //show form.
  115.                            ?>
  116.                             <form method="POST" id="license_no_update"">
  117.                                 <input type="text" name="license_no" value="License Number" />
  118.                             <input type="hidden" value="<?php echo $row['student_id']; ?>" name="student_id"  />
  119.                            
  120.                             </form>
  121.                             <div id="output"></div>
  122.                             <?php
  123.                          
  124.                        }else{
  125.                            //show license no.
  126.                            echo $row['license_no'];
  127.                        }
  128.                        ?></td>
  129.                         <td><?php echo $row['status']; ?></td>
  130.         </tr>
  131.                 <?php      
  132. }
  133. ?>
  134.     </tbody>
  135. </table></center>
  136.        
  137.     </body>
  138. </html>
Advertisement
Add Comment
Please, Sign In to add comment