-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsearch.php
More file actions
237 lines (203 loc) · 5.81 KB
/
search.php
File metadata and controls
237 lines (203 loc) · 5.81 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
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
<?php
session_start();
if(!isset($_SESSION['attusername'])){
die(header("location:index.php"));
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<!--<meta http-equiv="X-UA-Compatible" content="IE=edge"> -->
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Student Full Details</title>
<!-- Compiled and minified CSS
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/css/materialize.min.css"> -->
<link rel="stylesheet" href="css/materialize.min.css">
<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">
<style type="text/CSS">
/*enable for testing purpose
*{
box-shadow:1px 0px 3px orange;
}*/
#ru{
position:relative;
}
#delacc{
position:absolute;
right:0px;
color:grey;
}
button{
margin:13px;
}
.container{/*
margin-left:10%;
margin-right:12%;*/
}
.btn-small {
width:30%;
margin:8px;
margin-top: 30px;
}
.search-section{
margin:15px;
}
.input-field{
width: 80%;
}
header, main, footer {
padding-left: 300px;
}
@media only screen and (max-width : 992px) {
header, main, footer {
padding-left: 0;
}
}
</style>
</head>
<body>
<main>
<h5 class="container" style="margin:15px; margin-top: 20px">Search Individual Student Details</h5>
<div class="row search-section">
<!-- Default input -->
<form class="form-inline" method="GET" action="search.php">
<div class=" s5 input-field">
<input class="form-control m-2" type="search" name="stud" placeholder="Name or Reg No" required>
</div>
<div class=" s5 input-field">
<input class="form-control m-2 autocomplete" type="search" name="class" placeholder="Batch-Class-Section" required></div>
<div class=" input-field">
<button class="btn-small blue darken-1">Search</button>
</div>
</form>
</div>
<hr>
<div id="result" class="container">
<?php
if (isset($_GET["stud"])){
$n=preg_replace('/[^A-z0-9.\s]/', '', trim($_GET["stud"]));
$c=preg_replace('/[^A-Za-z0-9]/', '',strtoupper($_GET["class"]));
$gotValues=true;
}else{
$gotValues=false;
}
$servername = "localhost";
$username = "root";
$password = "";
$dbname = "Attendance";
// Create connection
$conn = new mysqli($servername, $username, $password,$dbname);
// Check connection
if ($conn->connect_error) {
die("<br>Connection failed: " . $conn->connect_error);
}
echo '<table class="striped left"><thead>
<tr> <th>Date</th> <th>Status</th> <th>Staff</th> </tr>
</thead> <tbody>';
if($gotValues==true){
$sql = "select * from $c where RegisterNumber='$n' or Name='$n' or RegisterNumber='1' ";
$result = $conn->query($sql);
//data of appropriate table
$sqc = "SELECT column_name from information_schema.columns where table_schema='Attendance' and table_name='$c' ";
$res = $conn->query($sqc);
//column name of the appropriate table from information_schema.columns
//echo $conn->error;
if ($result->num_rows > 0) {
//fetching the detail of who takes attendance
$staff = $result->fetch_array();
//$count=$result->field_count;
$row = $result->fetch_array();
//column is not idetifiable so fetch_array is used instead of associative array
$i=-1;
while ($col = $res->fetch_array()){
//data of tablename displayed while column name fetched,displayed in the information_schema
//print_r($col);
$i++; //start from zero
//if($i<0){ continue; }
echo '<tr> <td>'.$col[0].'</td> <td class="sr">';
if("P"==$row[$i]){ echo "Present";
}elseif("A"==$row[$i]){ echo "Absent";
}elseif("O"==$row[$i]){ echo "OnDuty"; }
elseif("N"==$row[$i]){ echo "NULL"; }
else{
//echo $row[$i];
echo "unknown";
}
echo '</td> <td class="sr">'.$staff[$i].'</td> </tr>';
//column name as col and data as row
//$i++;
}
//for($i=2;$i<$count;$i++){
//}
}
else{
echo '<tr><td colspan="3">0 results</td></tr>';
}
echo '</tbody> </table>';
}//if got values
?>
</div>
</main>
<!--side Nav -->
<ul id="slide-out" class="sidenav sidenav-fixed">
<div class="user-view">
<div class="background">
<img src="images/imgt.jpg">
</div>
<h6 class="white-text"> <?php echo $_SESSION['attusername']; ?></h6>
<div id="ru" class="row"> <p><a href = "logout.php">Sign Out</a> <a id="delacc">Delete Account</a></p>
</div>
</div>
<li class="nav-item"><a class="nav-link" href="main.php">Attendance</a></li>
<li class="nav-item"> <a class="nav-link" href="view.php">View</a> </li>
<li class="nav-item active"> <a class="nav-link " href="register.php">Register</a> </li>
</ul><!--col acc-->
<!-- Compiled and minified JavaScript -->
<!-- <script src="https://cdnjs.cloudflare.com/ajax/libs/materialize/1.0.0/js/materialize.min.js"></script> -->
<script src="js/materialize.js"></script>
<script src="js/materialize.min.js"></script>
<script src="vendor/jquery/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function(){
$(".sr").click(function(){
var txt=$(this).text().toLowerCase();
$("tbody tr").filter(function(){
$(this).toggle($(this).text().toLowerCase().indexOf(txt)>-1);
}); //fl
}); //clk
$("#delacc").click(function(e) {
$.ajax({
type: "POST",
url: 'main_backend.php',
data: {
a: "delaccount"
},
success: function(data) {
window.location = "timetable.html";
} //suc
}); //aj
}); //cl
}); //doc
</script>
<script> document.addEventListener('DOMContentLoaded', function() {
M.AutoInit();
var elems = document.querySelectorAll('.autocomplete');
options={'limit':7,'data':{
<?php
$sq= "SELECT distinct table_name from information_schema.columns where table_schema='Attendance' and table_name!='Staff' ";
$res = $conn->query($sq);
if ($res->num_rows > 0) {
while ($r = $res->fetch_array()){
echo ' "'.$r[0].'": null, ';
}}
if(isset($conn)){
$conn->close();
}
?>
}};
var instances = M.Autocomplete.init(elems, options);
});
</script>
</body>
</html>