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
| <?php
function rate($rate, $db, $foto_id) {
if(!is_numeric($rate) || ($rate < 1) || ($rate > 10)) {
return false;
}
$rate = (int)$rate;
$sql = 'INSERT INTO
`voting_rate` (`ArticleID`, `punte`, `date`)
VALUES
(?,?, NOW())';
$stmt = $db->prepare($sql);
$stmt->bind_param('ii', $foto_id, $rate);
$stmt->execute();
$result = $stmt->insert_id;
$stmt->close();
return (bool) $result;
}
function getVotes($db) {
$result = false;
$sql = 'SELECT
SUM(`punte`),
COUNT(*)
FROM
`voting_rate`';
$stmt = $db->prepare($sql);
$stmt->execute();
$stmt->bind_result($rate_sum, $rate_count);
while($stmt->fetch()) {
if($rate_count > 0) {
$result = array(
'RateSUM' => $rate_sum,
'RateCount' => $rate_count,
'Rate' => floor($rate_sum / $rate_count),
);
}
}
return $result;
}
$zufallsausgabe = 'SELECT * FROM `voting` ORDER BY RAND() LIMIT 1';
$ausgabe = mysql_query($zufallsausgabe);
while($row = mysql_fetch_assoc($ausgabe)) {
if(isset($_GET['rating'])) {
$result = rate($_GET['rating'], $db, $_GET['id']);
}
$votes = getVotes($db);
?>
<h2>Foto Voting</h2>
<!-- Top Image -->
<ul class="navigate">
<?php $i = 1; while($i <= 10): ?>
<?php if(is_array($votes) && $i <= $votes['Rate']): ?>
<li><a href="?rating=<?php echo $i ?>" class="active" title="<?php echo $i ?> Star"><?php echo $i ?></a></li>
<?php else: ?>
<li><a href="?rating=<?php echo $i ?>" title="<?php echo $i ?> Star"><?php echo $i ?></a></li>
<?php endif;?>
<?php ++$i; endwhile; ?>
</ul>
<div class="transparent-frame">
<div class="frame"> </div>
<img src="votingfotos/<?php echo $row['dateiname']; ?>" alt="" width="545" height="285" /><?php } ?>
</div>
<div class="cl"> </div> |
[PHP][Snippet] Array zu XML konvertieren