-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTrendingKeywords.php
87 lines (67 loc) · 2.1 KB
/
TrendingKeywords.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
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<meta name="author" content="Manzoor Ahmed" />
<title></title>
</head>
<body>
<?php
/**TrendingKeywords looks for user typed string in the `keyword` table first, if it not there, then it looks `course_data` to find this string
* For every find it increments the count in `word_hit` table
*
* @Author Manzoor Ahmed
**/
require_once 'connection.php';
if(isset($_POST['submit']))
{
$dbc =$GLOBALS['dbc'];
$word = $_POST['search'];
$find = "SELECT `id`
FROM `keywords`
WHERE `keywords`.`word`
LIKE '$word';";
$result = $dbc->query($find) or die($dbc->error);
if($result){
//increment hits
$row_id = $result->fetch_row();
$id = $row_id[0];
$get_hit = "SELECT `hits`
FROM `word_hits`
WHERE `id` = '$id'";
$run_get_hit = $dbc->query($get_hit) or die($dbc->error);
$old_row = $run_get_hit->fetch_row();
$old_hit = $old_row[0];
$new_hit = $old_hit +1;
$inc = "UPDATE `word_hits`
SET `hits` = '$new_hit'
WHERE `id` = '$id'";
$run = $dbc->query($inc) or die($dbc->error);
if($id == NULL){
//did not find it
$insert = "INSERT INTO `keywords`
(`id`,`word`)
VALUES ('0', '$word');";
$run = $dbc->query($insert) or die($dbc->error);
if($run){
$id =mysqli_insert_id($dbc);
$inc_hits = "INSERT INTO `word_hits`
(`id`, `hits`)
VALUES('$id','0')";
$run_hits = $dbc->query($inc_hits) or die($dbc->error);
}
}
}
}
?>
<form action="<?php echo $_SERVER['PHP_SELF'];?>" method="post">
<table width="100%">
<tr>
<td width="28%"><input type="text" name="search" id="search" size="35" value="Search" /></td>
<td width="12%"></td>
<td width="60%"><input type="submit" name="submit" id="submit" value="SEARCH" /></td>
</tr>
</table>
</form>
</body>
</html>