-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.php
67 lines (59 loc) · 1.96 KB
/
index.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
<?php
require 'connect.php';
require 'suggestion.class.php';
// Converting the IP to a number. This is a more effective way
// to store it in the database:
$ip = sprintf('%u', ip2long($_SERVER['REMOTE_ADDR']));
// The following query uses a left join to select
// all the suggestions and in the same time determine
// whether the user has voted on them.
$result = $mysqli->query("
SELECT
`s`.*,
IF (`v`.`ip` IS NULL, 0, 1) AS `has_voted`
FROM `suggestions` `s`
LEFT JOIN `suggestions_votes` `v` ON (`s`.`id` = `v`.`suggestion_id` AND `v`.`day` = CURRENT_DATE AND `v`.`ip` = $ip)
ORDER BY
`s`.`rating` DESC,
`s`.`id` DESC
");
$str = '';
if (!$mysqli->error) {
// Generating the UL
$str = '<ul class="suggestions">';
// Using MySQLi's fetch_object method to create a new
// object and populate it with the columns of the result query:
while ($suggestion = $result->fetch_object('Suggestion')) {
$str .= $suggestion; // Using the __toString() magic method.
}
$str .= '</ul>';
}
?>
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Feature Suggest for www.life-link.org</title>
<link rel="stylesheet" type="text/css" href="styles.css" />
</head>
<body>
<div id="page">
<div id="heading" class="rounded">
<h1>Suggestions<i>for <a href="http://www.life-link.org">www.life-link.org</a></i></h1>
<p>
Please let us know how we can improve our online presence.<br>
Vote for or against an existing suggestion or suggest something new!
</p>
</div>
<?php echo $str; ?>
<form id="suggest" action="" method="post">
<p>
<input type="text" id="suggestionText" class="rounded" maxlength="255" autocomplete="off" />
<input type="submit" value="Submit" id="submitSuggestion" />
</p>
</form>
</div>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script src="script.js"></script>
</body>
</html>