Example #1
0
        if (!isset($allArgs[$param]) || trim($allArgs[$param]) === "") {
            return false;
        }
    }
    return true;
}
if (!Session::userLoggedIn()) {
    header("Location: login.php");
    exit;
}
if (isset($_GET['searchKey'])) {
    if (trim($_GET['searchKey']) === "") {
        die("[]");
    }
    $searchKey = $_GET['searchKey'];
    $arrayOfCourses = Database::searchCourses($searchKey);
    $JSONArray = '[';
    //begin JSONArray string
    foreach ($arrayOfCourses as $record) {
        $id = $record['id'];
        $courseName = $record['name'];
        $semester = $record['semester'];
        $instructor = $record['instructor'];
        $JSONArray = $JSONArray . '{ "courseName": "' . $courseName . '",';
        $JSONArray = $JSONArray . '"id": "' . $id . '",';
        $JSONArray = $JSONArray . '"semester": "' . $semester . '",';
        $JSONArray = $JSONArray . '"instructor": "' . $instructor . '"';
        $JSONArray = $JSONArray . '},';
    }
    $JSONArray = rtrim($JSONArray, ",");
    //remove last comma