-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgetstatistics.php
43 lines (38 loc) · 1.63 KB
/
getstatistics.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
<?php
require_once('config.php');
require_once('dbconnect.php');
//get a list of the usernames and ids
$res_users = mysql_query ("SELECT `userid`, `username` FROM `users`") or die ("Error getting usernames: " . mysql_error() . "<br />");
while ($row=mysql_fetch_array($res_users)) {
$key = $row["userid"];
$userlist[$key] = $row["username"];
}
$timeframe = (int) $_GET['timeframe']; //data sanitization shortcut
if ($timeframe <= 0) {
header('HTTP/1.1 500 Internal Server Booboo');
header('Content-Type: application/json');
die('ERROR');
}
$sql = "SELECT COUNT(1) AS theCommentCount, `authorid`, `visible`, `createdate` FROM `comments`
WHERE `visible`='Y' AND DATEDIFF(CURDATE(), `createdate`) <= $timeframe
GROUP BY `authorid` ORDER BY theCommentCount DESC";
$res_comment_count = mysql_query($sql) or die ("Error getting comment count: " . mysql_error() . "<br/>");
$table = array();
$table['cols'] = array(
array('id'=>"", 'label'=>"Username", 'type'=>"string"),
array('id'=>"", 'label'=>"Searchlink", 'type'=>"string"),
array('id'=>"", 'label'=>"Posts", 'type'=>"number")
);
$rows = array();
while ($row2 = mysql_fetch_array($res_comment_count)) {
$username = $userlist[$row2['authorid']];
$cells = array();
$cells[] = array('v'=>$username);
$cells[] = array('v'=>"conversationsearch.php?q_author=$username&q_timeframe=$timeframe&q_title=&q_matchAllComments=matchall");
$cells[] = array('v'=>(int)$row2['theCommentCount']);
$rows[] = array('c'=>$cells);
}
$table['rows'] = $rows;
$jsontable = json_encode($table);
echo $jsontable;
?>