-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
186 lines (148 loc) · 7.22 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
include("admin/connection.php");
?>
<!DOCTYPE HTML>
<html class="no-js">
<head>
<!-- Basic Page Needs
================================================== -->
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>Light Of Truth Equipping Network</title>
<meta name="description" content="">
<meta name="keywords" content="">
<meta name="author" content="">
<!-- Mobile Specific Metas
================================================== -->
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0">
<meta name="format-detection" content="telephone=no">
<!-- CSS
================================================== -->
<link href="css/bootstrap.css" rel="stylesheet" type="text/css">
<link href="css/bootstrap-theme.css" rel="stylesheet" type="text/css">
<link href="css/style.css" rel="stylesheet" type="text/css">
<link href="vendor/prettyphoto/css/prettyPhoto.css" rel="stylesheet" type="text/css">
<link href="vendor/mediaelement/mediaelementplayer.css" rel="stylesheet" type="text/css">
<!--[if lte IE 9]><link rel="stylesheet" type="text/css" href="css/ie.css" media="screen" /><![endif]-->
<link href="css/custom.css" rel="stylesheet" type="text/css"><!-- CUSTOM STYLESHEET FOR STYLING -->
<!-- Color Style -->
<link class="alt" href="colors/color1.css" rel="stylesheet" type="text/css">
<link href="style-switcher/css/style-switcher.css" rel="stylesheet" type="text/css">
<link rel="shortcut icon" href="images/ltenlogo.png">
<!-- SCRIPTS
================================================== -->
<script src="js/modernizr.js"></script><!-- Modernizr -->
</head>
<body>
<div class="body">
<!-- Start Site Header -->
<?php include("header.php");?>
<!-- End Site Header -->
<!-- Start Page Header -->
<div class="page-header parallax clearfix" style="background-image:url(images/ph8.jpg);">
<div class="title-subtitle-holder">
<div class="title-subtitle-holder-inner">
<h2>Search Results</h2>
</div>
</div>
</div>
</div>
<?php
$error="";
if (isset($_GET['rr'])) {
$newid= $_GET['rr'];
}
//this up code is the get code for the id
$query = $_GET['query'];
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysqli_real_escape_string($conn,$query);
// makes sure nobody uses SQL injection
$lol="SELECT * FROM album_table WHERE `album_name` LIKE '%".$query."%'";
$raw_results = mysqli_query($conn,$lol);
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
if(mysqli_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysqli_fetch_array($raw_results)){
// $results = mysql_fetch_array($raw_results) puts data from database into array, while it's valid it does the loop
$success= $results['album_name'];
$pic=$results['album_img'];
// posts results gotten from database(title and text) you can also show id ($results['id'])
}
}
else{ // if there is no matching rows do following
$error=" No Match Found";
}
}
else{ // if query length is less than minimum
$error= "Minimum length is .$min_length ";
}
?>
<div class="main" role="main">
<div id="content" class="content full">
<div class="container">
<div class="row">
<ul class="isotope-grid">
<?php
if (isset($_GET['rr'])) {
$newid= $_GET['rr'];
}
//this up code is the get code for the id
$query = $_GET['query'];
// gets value sent over search form
$min_length = 3;
// you can set minimum length of the query if you want
if(strlen($query) >= $min_length){ // if query length is more or equal minimum length then
$query = htmlspecialchars($query);
// changes characters used in html to their equivalents, for example: < to >
$query = mysqli_real_escape_string($conn,$query);
// makes sure nobody uses SQL injection
$lol="SELECT * FROM album_table WHERE `album_name` LIKE '%".$query."%'";
$raw_results = mysqli_query($conn,$lol);
// * means that it selects all fields, you can also write: `id`, `title`, `text`
// articles is the name of our table
// '%$query%' is what we're looking for, % means anything, for example if $query is Hello
// it will match "hello", "Hello man", "gogohello", if you want exact match use `title`='$query'
// or if you want to match just full word so "gogohello" is out use '% $query %' ...OR ... '$query %' ... OR ... '% $query'
if(mysqli_num_rows($raw_results) > 0){ // if one or more rows are returned do following
while($results = mysqli_fetch_array($raw_results)){
?>
<li class="col-md-4 col-sm-6 sermon-item grid-item format-standard">
<div class="grid-item-inner">
<a class="media-box">
<img src="admin/album/<?php echo$results['album_img'] ?>" alt="">
</a>
<div class="grid-content">
<span class="sermon-series-date"><i style="font-size:10px; ">By : Light of Truth Equipping Network</i></span>
<h3><a href="sermon-details.php?rr=<?php echo $results['id'] ?>"><?php echo $results['album_name']; ?></a></h3>
<a href="sermon-details.php?rr=<?php echo $results['id'] ?>" class="btn btn-primary">View Tracks<i class="fa fa-chevron-right"></i></a>
</div>
</div>
</li>
<?php }
}
else{ // if there is no matching rows do following
$error=" No Match Found";
}
}
else{ // if query length is less than minimum
$error= "Please Input a Keyword ! Minimum length is .$min_length ";
}
?>
</ul>
<?php if ($error !=""){
echo "<h1 class='alert alert-danger alert-dismissable'>$error</h1>";
}
?>
</div>
</div>
</div>
</div>
</body>
</html>