-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstudents.php
More file actions
144 lines (121 loc) · 4.23 KB
/
students.php
File metadata and controls
144 lines (121 loc) · 4.23 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
<?php
if (!isset($_SESSION)) {
session_start();
}
// checks if loggedin
if (!isset($_SESSION['email'])) {
header('location: login.php');
}
require_once 'partials/header.php';
$limit = 10;
$page = isset($_GET['page']) ? $_GET['page'] : 1;
$start = ($page - 1) * $limit;
$sql = "SELECT * FROM students LIMIT " . $start . " , " . $limit;
$results = $conn->query($sql) or die($conn->error);
$students = $results->fetch_all(MYSQLI_ASSOC);
$total = $results->num_rows;
// count students
$sqlCount = "SELECT count(student_id) AS id FROM students";
$results1 = $conn->query($sqlCount) or die($conn->error);
$studentCount = $results1->fetch_all(MYSQLI_ASSOC);
$totalStudents = $studentCount[0]['id'];
$pages = ceil($totalStudents / $limit);
$previous = $page - 1;
$next = $page + 1;
?>
<?php require 'partials/innerNav.php'; ?>
<main class="sub-pages">
<div class="container-fluid">
<div class="row">
<div class="col-12">
<div class="inner-hero">
<img src="dist/images/reading.jpg" alt="bonding">
</div>
</div>
</div>
</div>
<!-- table -->
<div class="container student-record">
<div class="row">
<div class="col-12 record-data">
<!-- Checks if user is admin -->
<?php if (isset($_SESSION['user_type']) && $_SESSION['user_type'] == 1) : ?>
<div class="record-container">
<form action="search.php" method="get" class="searchForm">
<input type="text" class="form-control" name="search" id="searchInput" />
<button class="btn btn-primary custom-button">Search</button>
</form>
</div>
<?php endif; ?>
<!-- Checks if there is content -->
<?php if ($total > 0) : ?>
<table>
<thead>
<tr>
<th scope="col">Full Name</th>
<th scope="col">Last Name</th>
<th scope="col">Email</th>
<th scope="col">Gender</th>
<?php if (isset($_SESSION['user_type']) && $_SESSION['user_type'] == 1) : ?>
<th scope="col"></th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php foreach ($students as $student) :?>
<tr>
<td data-label="Full Name"><?= $student['full_name']; ?></td>
<td data-label="Last Name"><?= $student['last_name']; ?></td>
<td data-label="Email"><?= $student['email']; ?></td>
<td data-label="Gender"><?= $student['gender']; ?></td>
<?php if (isset($_SESSION['user_type']) && $_SESSION['user_type'] == 1) : ?>
<td><a href="view_details.php?stud_id=<?= $student['student_id']; ?>" class="btn btn-link view-record">View</a></td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
<?php else : ?>
<div class="no-record">
<h2>No Record Found.</h2>
<p>Let's try add one!</p>
</div>
<?php endif; ?>
</div>
</div>
<!-- Pagination -->
<nav aria-label="Page navigation">
<ul class="pagination">
<li class="page-item">
<?php if ($page > 1) : ?>
<a class="page-link" href="<?= "students.php?page=$previous"; ?>" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
<?php else : ?>
<a class="page-link disabled-button" href="#" aria-label="Previous">
<span aria-hidden="true">«</span>
</a>
<?php endif; ?>
</li>
<?php for($i = 1; $i <= $pages; $i++) : ?>
<li class="page-item"><a class="page-link" href="<?= "students.php?page=$i"; ?>"><?= $i; ?></a></li>
<?php endfor; ?>
<li class="page-item">
<?php if ($page < $pages) : ?>
<a class="page-link" href="<?= "students.php?page=$next"; ?>" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
<?php else : ?>
<a class="page-link disabled-button" href="#" aria-label="Next">
<span aria-hidden="true">»</span>
</a>
<?php endif; ?>
</li>
</ul>
</nav>
</div>
</div>
</main>
<?php
require_once 'partials/footer.php';
?>