-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhotalgorithm.php
More file actions
57 lines (42 loc) · 1.45 KB
/
Copy pathhotalgorithm.php
File metadata and controls
57 lines (42 loc) · 1.45 KB
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
<?php
include_once 'header.php';
include 'includes/dbh.inc.php';
include_once 'timeElapsedCalculator.php';
function hot($likes, $date) {
$timeSinceSubmission = ((strtotime(date('Y-m-d H:i:s')) - strtotime($date)) / 3600);
return $likes / pow($timeSinceSubmission+2, 1.8);
}
?>
<div class="posts">
<?php
$sql = "SELECT * FROM jaro_164222_newsposts3";
$result = mysqli_query($conn, $sql);
$newArray = array();
echo '<table border="0" cellpadding="0" cellspacing="0"><tbody>';
$counter = 0;
while ($row = mysqli_fetch_array($result)) {
$row['score'] = hot($row['likes'], $row['time']);
array_push($newArray, $row);
}
function sortByScore($a, $b)
{
$a = $a['score'];
$b = $b['score'];
if ($a == $b) return 0;
return ($a < $b) ? -1 : 1;
}
usort($newArray, 'sortByScore');
for ($x = count($newArray) - 1; $x >= 0; $x--) {
$row = $newArray[$x];
$timeElapsed = calculateTime($row['time']);
echo '<tr class="titleRow onePost">';
echo '<td><a href="openPostPage.php?id=' . $row["id"] . '">' . $row["title"] . '</a><a id="upvote" href="likes.php?id=' . $row["id"] . '&like=1">' .
' + </a><a id="downvote" href="likes.php?id=' . $row["id"] . '&like=-1"> - </a><br>';
echo '<span id="authorRow">Posted by <strong>' . $row["username"] . '</strong> | <i>' . $timeElapsed . '</i> | Score: ' . $row['likes'] . '</span></td></tr>';
}
echo '</tbody></table';
?>
</div>
</div>
</body>
</html>