-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.php
166 lines (159 loc) · 5.05 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
<?php include 'common.htm'; ?>
<?PHP
function getmicrotime()
{
list($usec, $sec) = explode(" ", microtime());
return ((float)$usec + (float)$sec);
}
$RESULTS_LIMIT=10;
if(isset($_GET['search_term']))
{
$search_term = stripslashes($_GET['search_term']);
if(!isset($first_pos))
{
$first_pos = "0";
}
$start_search = getmicrotime();
$sql_query = mysql_query("SELECT * FROM TBL_NAME WHERE MATCH(Title,Author,Category) AGAINST('$search_term')");
if($results = mysql_num_rows($sql_query) != 0)
{
$sql = "SELECT * FROM TBL_NAME WHERE MATCH(Title,Author,Category) AGAINST('$search_term') LIMIT $first_pos, $RESULTS_LIMIT";
$sql_result_query = mysql_query($sql);
}
else
{
$sql = "SELECT * FROM TBL_NAME WHERE (Title LIKE '%".mysql_real_escape_string($search_term)."%' OR Author LIKE '%".$search_term."%' OR Category LIKE '%".$search_term."%') ";
$sql_query = mysql_query($sql);
$results = mysql_num_rows($sql_query);
$sql_result_query = mysql_query("SELECT * FROM TBL_NAME WHERE (Title LIKE '%".mysql_real_escape_string($search_term)."%' OR Author LIKE '%".$search_term."%' OR Category LIKE '%".$search_term."%') LIMIT $first_pos, $RESULTS_LIMIT ");
}
$stop_search = getmicrotime();
//calculating the search time
$time_search = ($stop_search - $start_search);
}
?>
<?PHP
if($results != 0)
{
?>
<div class="row">
<div class="col s4"> </div>
<div class="col s4">
You searched for <?php echo "<i><b><font color=#000000>".$search_term."</font></b></i> "; ?>
We found <b>
</b>
<b><?PHP echo $results; ?> results</b>
<div class="row">
<div class="col s12">
<form action="" method="GET">
<input name="search_term" type="text" value="<?PHP echo $search_term; ?>" size="40">
<input name="search_button" type="submit" value="Search">
</form>
</div>
</div>
<?PHP
while($row = mysql_fetch_array($sql_result_query))
{
$author=$row['Author'];
$pic="$author.jpg"
?>
<div class="row">
<div class="col s12">
<div class='card small hoverable news'>
<div class='card-image' style='background:url(<?php echo $row['Image']; ?>); background-size:cover; background-position:center center;'>
<a style='background: rgb(0, 0, 0); background: rgba(0, 0, 0, 0.7);height:100%;width:100%;' class='card-title'><?php echo $row['Title']; ?></a>
</div>
<div class='card-content'>
<div style='background:url(pics/<?php echo $pic; ?>);background-size:cover; background-position: center center;' class='team1'></div>
<a id='author'><?php echo $author; ?></a>
<a id='date'><?php echo $row['Date']; ?></a>
</div>
<div style='text-align:center;' class='card-action'>
<a style='color:#E65100;' href='<?php echo $row["Link"]; ?>'>Read Now</a>
</div>
</div>
</div>
</div>
<?PHP
}
?>
</div>
</div>
<?PHP
}
elseif($sql_query)
{
?>
<table border="0" cellspacing="2" cellpadding="0">
<tr>
<td align="center">No results for <?PHP echo "<i><b><font color=#000000>".$search_term."</font></b></i> "; ?></td>
</tr>
<tr>
<form action="" method="GET">
<td colspan="2" align="center">
<input name="search_term" type="text" value="<?PHP echo $search_term; ?>">
<input name="search_button" type="submit" value="Search">
</td>
</form>
</tr>
</table>
<?PHP
}
?>
<table width="300" border="0" cellspacing="0" cellpadding="0">
<?php
if (!isset($_GET['search_term'])) { ?>
<tr>
<form action="" method="GET">
<td colspan="2" align="center">
<input name="search_term" type="text" value="<?PHP echo $search_term; ?>">
<input name="search_button" type="submit" value="Search">
</td>
</form>
</tr>
<?php
}
?>
<tr>
<td align="right">
<?PHP
//displaying the number of pages where the results are sittuated
if($first_pos > 0)
{
$back=$first_pos-$RESULTS_LIMIT;
if($back < 0)
{
$back = 0;
}
echo "<a href='search.php?search_term=".stripslashes($search_term)."&first_pos=$back' ></a>";
}
if($results>$RESULTS_LIMIT)
{
$sites=intval($results/$RESULTS_LIMIT);
if($results%$RESULTS_LIMIT)
{
$sites++;
}
}
for ($i=1;$i<=$sites;$i++)
{
$fwd=($i-1)*$RESULTS_LIMIT;
if($fwd == $first_pos)
{
echo "<a href='search.php?search_term=".stripslashes($search_term)."&first_pos=$fwd '><b>$i</b></a> | ";
}
else
{
echo "<a href='search.php?search_term=".stripslashes($search_term)."&first_pos=$fwd '>$i</a> | ";
}
}
if(isset($first_pos) && $first_pos < $results-$RESULTS_LIMIT)
{
$fwd=$first_pos+$RESULTS_LIMIT;
echo "<a href='search.php?search_term=".stripslashes($search_term)."&first_pos=$fwd ' > >></a>";
$fwd=$results-$RESULTS_LIMIT;
}
?>
</td>
</tr>
</table>