Permalink
Cannot retrieve contributors at this time
Name already in use
A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
206cde/arsearch.php
Go to fileThis commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
79 lines (70 sloc)
2.29 KB
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// Return: Lecturer, CurrentLecture, Time, NextLecture | |
//error_reporting(E_ALL & ~E_NOTICE); | |
$servername = "localhost"; | |
$username = "root"; | |
$password = ""; | |
$dbname = "appdb"; | |
// Create connection | |
$conn = new mysqli($servername, $username, $password, $dbname); | |
// Check connection | |
if ($conn->connect_error) { | |
die("Connection failed: " . $conn->connect_error . "<br>"); | |
} | |
// Connect to database | |
/* TESTING | |
$room_name = "ec115"; | |
$day_week = "Friday"; | |
$time_current = "16"; | |
*/ | |
//* | |
$room_name = $_POST["room_name"]; | |
$day_week = $_POST["day_week"]; | |
$time_current = $_POST["time_current"]; | |
//*/ | |
// Check room | |
$query_room = "SELECT * FROM $room_name WHERE day_week='" . $day_week . "'"; | |
$check_room = mysqli_query($conn, $query_room) or die ("Check Failed Room"); | |
$fetched_room = mysqli_fetch_assoc($check_room); | |
// Empty day | |
if ($fetched_room == 0){ | |
echo "empty\t" . "\t" . "day off\t" . "\t"; | |
exit(); | |
} | |
// Empty Hour | |
else if (is_null($fetched_room[$time_current])){ | |
echo "empty\t"; | |
for ($i = $time_current; $i <= 18; $i++){ | |
if (!is_null($fetched_room[$i])){ | |
// Check Lecturer | |
$query_lecturer = "SELECT * FROM $fetched_room[$i] WHERE day_week='" . $day_week . "'"; | |
$check_lecturer = mysqli_query($conn, $query_lecturer) or die("Check failed Lecturer"); | |
$fetched_lecturer = mysqli_fetch_assoc($check_lecturer); | |
echo "\t" . $i . "\t" . $fetched_lecturer[$i]; | |
exit(); | |
} | |
} | |
echo "\t" . "day off\t" . "\t"; | |
exit(); | |
} | |
// Occupied | |
else{ | |
// Check Lecturer | |
$query_lecturer = "SELECT * FROM $fetched_room[$time_current] WHERE day_week='" . $day_week . "'"; | |
$check_lecturer = mysqli_query($conn, $query_lecturer) or die("Check failed Lecturer"); | |
$fetched_lecturer = mysqli_fetch_assoc($check_lecturer); | |
echo $fetched_room[$time_current] . "\t" . $fetched_lecturer[$time_current] . "\t"; | |
for ($i = $time_current; $i <= 18; $i++){ | |
// Empty next | |
if (is_null($fetched_room[$i])){ | |
echo $i . "\t" . "empty"; | |
exit(); | |
} | |
// Occupied next | |
if ($fetched_lecturer[$i] != $fetched_lecturer[$time_current]){ | |
echo $i . "\t" . $fetched_lecturer[$i]; | |
exit(); | |
} | |
} | |
} | |
?> |