Advertisement
Guest User

Untitled

a guest
Sep 25th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. <html>
  2. <title>Lab 4</title>
  3. <body>
  4.  
  5. <h1 style="font-size:50px;">Select Query</h1>
  6.  
  7. <form action="lab4.php" method="post">
  8. <select name="formQuery" style="font-size:30px;">
  9. <option value='blank'>Select...</option>
  10. <option value='showAll'>Show All Classes</option>
  11. <option value='showStart'>Show All Classes' Start Times</option>
  12. <option value='showCS'>Show All Computer Science Classes</option>
  13. <option value='showMWF'>Show MWF Classes</option>
  14. <option value='showTotal'>Show All Classes' Total Times</option>
  15. </select>
  16.  
  17. <input style="font-size:30px;display:block;margin-top:30px;" type="submit">
  18. </form>
  19.  
  20. </body>
  21.  
  22. <?php
  23.  
  24. if($_POST['formQuery'] == "blank")
  25. {
  26. print "<h1>Select a query from the dropdown!</h1>";
  27. exit();
  28. }
  29.  
  30. $servername = "localhost";
  31. $username = "tws6d9";
  32. $password = "flal3511";
  33. $dbname = "tws6d9";
  34.  
  35. $conn = new mysqli($servername, $username, $password, $dbname);
  36. if ($conn->connect_error) {
  37. die("Connection failed: " . $conn->connect_error);
  38. }
  39.  
  40. else if($_POST['formQuery'] == "showAll")
  41. {
  42. $sql = "SELECT * FROM classes";
  43.  
  44. $result = $conn->query($sql);
  45.  
  46. if ($result->num_rows > 0)
  47. {
  48. while($row = $result->fetch_assoc())
  49. {
  50. print "<p style='font-size:30px;'>Class name: " . $row['name'] . ", Department: " . $row['department'] .
  51. ", Course ID: " . $row['course_id'] . ", Days: " . $row['days'] . "</p><br>";
  52. }
  53. }
  54.  
  55. exit();
  56. }
  57.  
  58. else if($_POST['formQuery'] == "showStart")
  59. {
  60. $sql = "SELECT start FROM classes AS startTimes";
  61.  
  62. $result = $conn->query($sql);
  63.  
  64. if ($result->num_rows > 0)
  65. {
  66. while($row = $result->fetch_assoc())
  67. {
  68. print "<p style='font-size:30px;'>Class name: " . $row['name'] .
  69. }
  70. }
  71. }
  72.  
  73. else if($_POST['formQuery'] == "showCS")
  74. {
  75. $sql = "SELECT name, department FROM classes WHERE department = 'Mathematics'";
  76.  
  77. $result = $conn->query($sql);
  78.  
  79. if ($result->num_rows > 0)
  80. {
  81. while($row = $result->fetch_assoc())
  82. {
  83.  
  84. }
  85. }
  86. }
  87.  
  88. else if($_POST['formQuery'] == "showMWF")
  89. {
  90. $sql = "SELECT * FROM classes WHERE days = 'MWF'";
  91.  
  92. $result = $conn->query($sql);
  93.  
  94. if ($result->num_rows > 0)
  95. {
  96. while($row = $result->fetch_assoc())
  97. {
  98.  
  99. }
  100. }
  101. }
  102.  
  103. else if($_POST['formQuery'] == "showTotal")
  104. {
  105. $sql = "SELECT name, TIMEDIFF(classes.end, classes.start) AS classLength FROM classes";
  106.  
  107. $result = $conn->query($sql);
  108.  
  109. if ($result->num_rows > 0)
  110. {
  111. while($row = $result->fetch_assoc())
  112. {
  113.  
  114. }
  115. }
  116. }
  117. ?>
  118.  
  119. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement