-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathviews.php
More file actions
executable file
·35 lines (28 loc) · 788 Bytes
/
views.php
File metadata and controls
executable file
·35 lines (28 loc) · 788 Bytes
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
<?php
require_once 'database/db_util.php';
if (isset($_POST["url"])) {
$url = $_POST["url"];
$mysqli = get_job_lube_db_conn();
$result = $mysqli->query("SELECT views FROM `viewed_posts` WHERE url='$url'");
if ($result && $result->num_rows > 0) {
$mysqli->query("UPDATE `viewed_posts` SET views=views+1 WHERE url='$url'");
} else {
$mysqli->query("INSERT INTO `viewed_posts` (url) VALUES ('$url')");
}
$mysqli->close();
}
function get_views($url) {
$mysqli = get_job_lube_db_conn();
$query = "SELECT views FROM `viewed_posts` where url='$url' limit 1";
$result = $mysqli->query($query);
if ($result && $result->num_rows > 0) {
$row = $result->fetch_row();
$count = $row[0];
$result->free();
} else {
$count = 0;
}
$mysqli->close();
return $count;
}
?>