Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <html>
- <title>Lab 4</title>
- <body>
- <h1 style="font-size:50px;">Select Query</h1>
- <form action="lab4.php" method="post">
- <select name="formQuery" style="font-size:30px;">
- <option value='blank'>Select...</option>
- <option value='showAll'>Show All Classes</option>
- <option value='showStart'>Show All Classes' Start Times</option>
- <option value='showCS'>Show All Computer Science Classes</option>
- <option value='showMWF'>Show MWF Classes</option>
- <option value='showTotal'>Show All Classes' Total Times</option>
- </select>
- <input style="font-size:30px;display:block;margin-top:30px;" type="submit">
- </form>
- </body>
- <?php
- if($_POST['formQuery'] == "blank")
- {
- print "<h1>Select a query from the dropdown!</h1>";
- exit();
- }
- $servername = "localhost";
- $username = "tws6d9";
- $password = "flal3511";
- $dbname = "tws6d9";
- $conn = new mysqli($servername, $username, $password, $dbname);
- if ($conn->connect_error) {
- die("Connection failed: " . $conn->connect_error);
- }
- else if($_POST['formQuery'] == "showAll")
- {
- $sql = "SELECT * FROM classes";
- $result = $conn->query($sql);
- if ($result->num_rows > 0)
- {
- while($row = $result->fetch_assoc())
- {
- print "<p style='font-size:30px;'>Class name: " . $row['name'] . ", Department: " . $row['department'] .
- ", Course ID: " . $row['course_id'] . ", Days: " . $row['days'] . "</p><br>";
- }
- }
- exit();
- }
- else if($_POST['formQuery'] == "showStart")
- {
- $sql = "SELECT start FROM classes AS startTimes";
- $result = $conn->query($sql);
- if ($result->num_rows > 0)
- {
- while($row = $result->fetch_assoc())
- {
- print "<p style='font-size:30px;'>Class name: " . $row['name'] .
- }
- }
- }
- else if($_POST['formQuery'] == "showCS")
- {
- $sql = "SELECT name, department FROM classes WHERE department = 'Mathematics'";
- $result = $conn->query($sql);
- if ($result->num_rows > 0)
- {
- while($row = $result->fetch_assoc())
- {
- }
- }
- }
- else if($_POST['formQuery'] == "showMWF")
- {
- $sql = "SELECT * FROM classes WHERE days = 'MWF'";
- $result = $conn->query($sql);
- if ($result->num_rows > 0)
- {
- while($row = $result->fetch_assoc())
- {
- }
- }
- }
- else if($_POST['formQuery'] == "showTotal")
- {
- $sql = "SELECT name, TIMEDIFF(classes.end, classes.start) AS classLength FROM classes";
- $result = $conn->query($sql);
- if ($result->num_rows > 0)
- {
- while($row = $result->fetch_assoc())
- {
- }
- }
- }
- ?>
- </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement