-
Notifications
You must be signed in to change notification settings - Fork 0
/
search-subjects.php
103 lines (90 loc) · 3.01 KB
/
search-subjects.php
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
<?php
session_start();
require_once("config.php");
include("db.php");
include("functions.php");
$pageTitle = "ค้นหาข้อสอบ - " . $cfg['title'];
include("head.php");
include("sidebar.php");
?>
<script type="text/javascript">
$(function(){
$("#searchbox").focus();
$("tr").click( function() {
if ($(this).find('a').attr('href'))
window.document.location = $(this).find('a').attr('href');
});
});
</script>
<?php
// Get q
$q = (isset($_GET['q']) ? $_GET['q'] : "");
?>
<div id="content" class="large-8 medium-8 medium-pull-4 columns">
<h1><span>ค้นหาข้อสอบ</span></h1>
<div class="panel">
<div class="row">
<form id="searchfrm" method="get" action="">
<div class="medium-12 columns">
<label for="searchbox">ค้นหา</label>
<div class="medium-9 columns">
<input type="text" name="q" id="searchbox" placeholder="ค้นหาจาก รหัสหรือชื่อวิชา" value="<?php echo $q; ?>">
</div>
<div class="medium-3 columns">
<button type="submit" id="btnsearch" class="liblue smallbtn">ค้นหา</button>
</div>
</div>
</form>
</div>
</div>
<?php
// Set empty variable
$sub_id = "";
$top_id = "";
// Set query
/*
SELECT * FROM subject s LEFT JOIN topics t on (s.sub_id = t.sub_id)
WHERE s.sub_id like '%' and s.sub_name like '%คณิต%' and t.top_name like '%ตรร%'
*/
$db->Table = "subject s LEFT JOIN topics t ON ( s.sub_id = t.sub_id ) ";
$db->Where = "1 ";
if ($q) {
$db->Where .= "and s.sub_id like '".($q == "" ? "%" : "%".$q."%")."'
or s.sub_name like '".($q == "" ? "%" : "%".$q."%")."'
or t.top_name like '".($q == "" ? "%" : "%".$q."%")."'";
//echo $db->Where;
}
$Stu_Data = $db->Select();
echo ' <table class="dc_table_s12" summary="Subjects list" style="width: 100%">
<thead>
<tr>
<th scope="col" style="text-align: center;">รหัสวิชา</th>
<th scope="col" style="text-align: center;">วิชา</th>
<th scope="col" style="text-align: center;">หมวด</th>
</tr>
</thead>
<tbody>';
if ($Stu_Data) {
// Students
foreach ($Stu_Data as $value) {
// Start Row
echo '<tr>';
echo '<th scope="row" style="text-align: center;"><a href="view-question.php?sub='.$value['Sub_id'].'&top='.$value['Top_id'].'"><strong>'.$value['Sub_id'].'</strong></a></th>';
echo '
<td style="text-align: center;">'.$value['Sub_name'].'</td>
<td style="text-align: center;">'.$value['Top_name'].'</td>';
// End Row
echo '</tr>';
}
} else {
echo '<td style="text-align: center;" colspan="3">ไม่พบรายการที่ค้นหา</td>';
}
?>
<tfoot>
<tr>
<td style="text-align: left" colspan="3">วิชาทั้งหมด <?php echo count($Stu_Data); ?> รายการ</td>
</tr>
</tfoot>
</table>
</div>
<?php include("footer.php");