Courses.php: improve search logic

Bug430-Eden2
Lan Hui 2023-09-07 19:49:35 +08:00
parent 79a928354b
commit 1cac6bebea
1 changed files with 7 additions and 8 deletions

View File

@ -510,14 +510,13 @@ include 'Header.php';
// current academic year - i.e 2021 - 2022 , so we will show in search result:
// course containing either 2021 or 2022 as academic year.
$oldest_academic_year = date('Y') - 1;
if(!empty($_GET["search"]) || !empty($_GET["faculty"]))
{
if (!empty($_GET["search"]) || !empty($_GET["faculty"])) {
$search = trim(mysqli_real_escape_string($con, $_GET["search"]));
$search = strtoupper($_GET['search']);
$search = strtoupper($search); # was strtoupper($_GET['search']);
$faculty = mysqli_real_escape_string($con, $_GET["faculty"]);
// the user has not entered something under "Find course by Code"
if($faculty=="")
if($search != "" && $faculty == "")
{
echo "<h4>Search results for course code: $search </h4><hr>";
$result = mysqli_query($con,"SELECT `Course_ID`, `Course_Name`, `Academic_Year`, `Faculty`,"
@ -526,7 +525,7 @@ include 'Header.php';
. " ON users_table.User_ID=courses_table.Lecturer_User_ID where Academic_Year >= $oldest_academic_year and Course_Code like '%{$search}%' and courses_table.Course_ID not in (select course_id from course_students_table where Student_ID=$student_id) order by Academic_Year desc");
}
// the user has entered something under "Find course by Code"
else
else if ($faculty != "")
{
echo "<h3> Find courses under faculty: $faculty</h3>";
$result = mysqli_query($con,"SELECT `Course_ID`, `Course_Name`, `Academic_Year`, `Faculty`,