Skip to content
Snippets Groups Projects
Commit 5993c1b4 authored by MHEN2606's avatar MHEN2606
Browse files

refactor: University Students Pagination

parent 3e81200d
No related merge requests found
......@@ -24,25 +24,48 @@ INNER JOIN (
university_id
) counts ON uni.university_id = counts.university_id";
$query1 = "SELECT count(*) AS count FROM
university uni
INNER JOIN student s ON uni.university_id = s.university_id
INNER JOIN user u ON s.user_id = u.user_id
INNER JOIN (
SELECT
university_id,
COUNT(*) AS applicant_count
FROM
student
GROUP BY
university_id
) counts ON uni.university_id = counts.university_id";
$whereClauses = [];
$params = [];
$params1 = [];
$types = "";
$types1 = "";
if(isset($_GET["uid"]) && $_GET['uid'] != NULL){
$whereClauses[] = " uni.university_id = ? ";
$params[] = $_GET['uid'];
$params1[] = $_GET['uid'];
$types .= 'i';
$types1 .= "i";
}
if(isset($_GET["name"]) && ($_GET['name'] != NULL || $_GET['name'] == "undefined") ){
if(isset($_GET["name"]) && ($_GET['name'] != NULL || $_GET['name'] != "undefined") ){
$whereClauses[] = ' u.name LIKE ? ';
$params[] = "%".$_GET['name']."%";
$types .= 's';
$params1[] = "%".$_GET['name']."%";
$types1 .= 's';
}
if($whereClauses != NULL){
$query .= ' WHERE '.implode(" AND ", $whereClauses);
$query1 .= ' WHERE '.implode(" AND ", $whereClauses);
}
if(isset($_GET["currentpage"]) && $_GET["currentpage"] != NULL){
$query .= "LIMIT ? OFFSET ?";
$offset = ($_GET['currentpage'] - 1) * $_GET['itemsperpage'];
......@@ -58,5 +81,18 @@ if($types != ''){
$result = mysqli_stmt_execute($stmt);
$row = mysqli_fetch_all(mysqli_stmt_get_result($stmt), MYSQLI_ASSOC);
echo json_encode($row);
$stmt1 = $db->setSTMT($query1);
if($types != ''){
mysqli_stmt_bind_param($stmt1, $types1, ...$params1);
}
$result = mysqli_stmt_execute($stmt1);
$total = mysqli_fetch_all(mysqli_stmt_get_result($stmt1), MYSQLI_ASSOC);
$response = [
'data' => $row,
'currentPage' => isset($_GET["currentpage"])?$_GET["currentpage"] : 0,
'total' => $total[0]["count"],
];
echo json_encode($response);
?>
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment