Advertisement
Guest User

Untitled

a guest
Jan 15th, 2016
71
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.76 KB | None | 0 0
  1. $('#showCourse').click(function(){
  2. console.log("showCourse");
  3. var top3 = $('#top3').val();
  4. var top3Table = $('#top3Table');
  5. console.log(top3);
  6. $.ajax({
  7. type: "POST",
  8. dataType:"json",
  9. data: {"top3" : top3},
  10. url: "jsonTop3.php",
  11. cache: false,
  12. success: function(data){
  13. console.log("success");
  14. console.log(data.length);
  15. for (var i = 0; i < data.length; i++) {
  16. var row = "<tr><td>" + data[i].student_id + "</td>" +
  17. "<td>" + data[i].grade + "</td></tr>";
  18. top3Table.append(row);
  19. }
  20. }
  21. });
  22. });
  23.  
  24. <div class="container">
  25. <div class="insertData" style="height:180px;">
  26. <h3>Pick Course name:</h3>
  27. <form class="form-horizontal">
  28. <select class="form-control" id="top3" onchange="document.getElementById('text_content').value=this.options[this.selectedIndex].text">
  29. <option>None</option>
  30. <option>Operational Systems</option>
  31. <option>Integrators</option>
  32. <option>Web Development</option>
  33. <option>Algebra</option>
  34. <option>Chimestry</option>
  35. <option>Biology</option>
  36. <option>History</option>
  37. <option>JAVA</option>
  38. <option>Intro to Math</option>
  39. <option>UNIX</option>
  40. </select>
  41. <input type="hidden" name="hid" id="text_content" value="">
  42. </form>
  43. <div class="rightButtons">
  44. <button type="add" name="type" class="btn btn-success" id="showCourse">Show</button>
  45. </div>
  46. </div>
  47. <div class="table">
  48. <h2>Top 3 Table</h2>
  49. <table class="table table-striped">
  50. <thead>
  51. </thead>
  52. <tbody id = "top3Table">
  53. </tbody>
  54. </table>
  55. </div>
  56. </div>
  57. <script src="script.js"></script>
  58. </body>
  59. </html>
  60.  
  61. <?php
  62.  
  63. function printStudents() {
  64. $host="127.0.0.1";
  65. $port=3306;
  66. $user="root";
  67. $password="root";
  68. $dbname="courcessystem";
  69.  
  70. $con = new mysqli($host, $user, $password, $dbname, $port)
  71. or die ('Could not connect to the database server' . mysqli_connect_error());
  72.  
  73.  
  74. $sql = "SELECT * FROM reg_courses
  75. ORDER BY course_id ASC";
  76. $result = mysqli_query($con, $sql) or die("Error in Selecting " . mysqli_error($con));
  77.  
  78. $emparray = array();
  79. while($row =mysqli_fetch_assoc($result)) {
  80. $emparray[] = $row;
  81. }
  82.  
  83. echo json_encode($emparray);
  84. $con->close();
  85. }
  86.  
  87. printStudents();
  88.  
  89. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement