-
Notifications
You must be signed in to change notification settings - Fork 0
/
search.php
186 lines (148 loc) · 6.99 KB
/
search.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
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
<?php
define("ROW_PER_PAGE",1); //Records to display per page
$title = 'Search Results';
include 'views/layout/header.php';
?>
<div class="container">
<div class="row">
<div class="col-md-6 col-md-offset-3">
<?php
$search = '';
if (!empty($_GET['search'])) {
$search = $_GET['search'];
/* Search Entry */
$keywords = explode(' ', $search);
$arr_length = count($keywords);
$sub_query = '';
for ($i = 0; $i < $arr_length; $i++) {
if ($i == 0) {
$sub_query = $sub_query . 'sym_tags LIKE "%' . $keywords[$i] . '%" OR sym_tags LIKE "%' . $keywords[$i] . '%"';
}else {
$sub_query = $sub_query . ' OR sym_tags LIKE "%' . $keywords[$i] . '%" OR sym_tags LIKE "%' . $keywords[$i] . '%"';
}
}
/* Query */
$query = 'SELECT * FROM symptoms WHERE ' . $sub_query;
/*Pagination Code Starts */
$per_page_htm = '';
$page = 1;
$start = 0;
if(!empty($_GET['r'])) {
$page = $_GET['r'];
$start = ($page - 1) * ROW_PER_PAGE;
}
$limit = "LIMIT " . $start . "," . ROW_PER_PAGE;
/* Getting Row Count Tested Working */
$p_query = 'SELECT COUNT(*) FROM symptoms WHERE ' . $sub_query;
$pag_stnt = $con->query($p_query);
$row_count = $pag_stnt->fetchColumn();
echo "<h4>You have $row_count result(s)</h4>";
if (!empty($row_count)) {
$per_page_htm .= "<div style='text-align:center;margin:20px 0px;'>";
$page_count = ceil($row_count / ROW_PER_PAGE);
if ($page_count > 1) {
$self = $_SERVER['PHP_SELF'];
$page_count = $page_count +1;
for($i=1; $i<=$page_count; $i++){
if($i==$page){
$per_page_htm .= "<a href='".$self."?r=".$i."&search=".urlencode($search)."' class='btn-page current'>".$i."</a>";
}elseif($i < $page_count){
$per_page_htm .= "<a href='".$self."?r=".$i."&search=".urlencode($search)."' class='btn-page'>".$i."</a>";
}
elseif($i == $page_count){
$per_page_htm .= "<a href='answer.php?search=".urlencode($search)."' class='btn btn-danger'>If none worked,Click Here</a>";
}elseif($i > $page_count){
header('Location:index.php');
}else{
echo "error";
}
}
}
$per_page_htm .= "</div>";
$n_query = 'SELECT * FROM symptoms WHERE ' . $sub_query . ' '.$limit ;
foreach ($con->query($n_query) as $row) {
$sym_cat_id = $row['cat_id'];
$sym_pro = $row['sym_pro'];
$sym_body = $row['sym_body'];
$sym_ans = $row['sym_answer'];
?>
<!-- Symptom Area-->
<div class="panel-group results">
<div class="panel panel-success">
<div class="panel-heading">
<p><?php //echo $cat_title;?></p>
<?php echo $search; ?>
</div>
<div class="panel-body">
<?php echo $sym_ans; ?>
<?php //echo $sym_ans;?></p>
<p><h4 class="text-center">Was the answer helpful</h4></p>
<p>
<a href="index.php" class="btn btn-info">YES</a>
<?php
if ($row_count == 1) {
echo "<a href='answer.php?search=".urlencode($search)."' class='btn btn-warning pull-right'>NO</a>";
}
?>
</p>
</div>
</div>
</div>
<?php
}
}else{
echo '<script>
setTimeout(function(){
swal({
title: "Sorry!",
text: "Your Query is not in our database",
type: "info"
}, function(){
window.location = "index.php";
});
}, 1000);
</script>';
}
echo $per_page_htm;
}else{
echo '<script>
setTimeout(function(){
swal({
title: "Oops!",
text: "Please enter a valid value!",
type: "error"
}, function(){
window.location = "index.php";
});
}, 1000);
</script>
';
}
?>
</div>
<div class="col-md-6 col-md-offset-3">
<div class="well text-center"">
<h4>Questions Directory</h4>
<p>Symptom Problem</p>
<?php
$query = "SELECT sym_tags FROM symptoms";
$r_query = $con->prepare($query);
$r_query->execute();
?>
<?php
while ($row = $r_query->fetch(PDO::FETCH_ASSOC)) {
$sym_tags = explode(",", $row['sym_tags']);
foreach ($sym_tags as $sym_tag) {
echo '<a href="result_tags.php?tag=' . $sym_tag . '" class="btn btn-info">' . $sym_tag . '</a> ';
}
}
?>
</div>
</div>
</div>
<div row>
</div>
</div>
<?php
include 'views/layout/footer.php'
?>