-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathKeywords.php
65 lines (51 loc) · 1.69 KB
/
Keywords.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
<?php
/*******************************************************************
*search for trending keywords and output the results
*
*@Author Manzoor Ahmed
******************************************************************/
class OutputKeywords{
var $maxSearch = 5; //search for only top 5,
var $maxShow =5; //show only 5 rows
function showKeywords($dbc){
$query = $dbc->real_escape_string("SELECT * from `keywords` WHERE `hits` >= 5 ORDER BY hits DESC LIMIT 5;");
$query_run = $dbc->query($query) or die($dbc->error);
if($query_run){
echo '<div class="keyword"><span class="muted">Trending Keywords:</span> ';
while($row = mysqli_fetch_array($query_run)){
echo '<a style="text-decoration:underline;" href="index.php?search='.
$row[1] . '&submit=KaZoom+It">' . $row[1] . "</a> ";
}
echo "</div>";
}
}
/**
* update hits for each keyword
* @param $dbc, connection to the database
& @param $word, the keyword which needs to be incremented
*/
function updateKeywords($dbc, $word){
$keyword = $dbc->real_escape_string($word);
if ($keyword === "") {
return;
}
$keyword = strtolower($keyword);
$query = "SELECT * FROM keywords WHERE word='$keyword'";
$result = $dbc->query($query) or die($dbc->error);
//echo $query;
if($result && $result->num_rows) {
$row = $result->fetch_array();
$id = $row['id'];
$hits = $row['hits'];
$hits++;
$que = "UPDATE keywords SET hits='$hits'
WHERE id='$id'";
$dbc->query($que);
} else {
$que = "INSERT INTO keywords (word, hits)
VALUES ('$keyword', '1')";
$dbc->query($que);
}
}//function
}//class
?>