Parantatatam
mag Cookies & Kekse
Dann verwendest du in deiner Datei voting.php auf Zeile 44 deine eigene Funktion falsch. Mich würde das Skript um diesen Bereich herum interessieren.
Folge dem Video um zu sehen, wie unsere Website als Web-App auf dem Startbildschirm installiert werden kann.
Anmerkung: Diese Funktion ist in einigen Browsern möglicherweise nicht verfügbar.
$result = rate($_GET['rating'], $db);
<?php
$zufallsausgabe = "SELECT * FROM voting ORDER BY RAND() LIMIT 1";
$ausgabe = mysql_query($zufallsausgabe);
while ($row = mysql_fetch_assoc($ausgabe)) {
function rate($rate, $db, $foto_id ) {
if(!is_numeric($rate)) return false;
$rate = (int)$rate;
if($rate < 1 || $rate >10) return false;
$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;
}
if(isset($_GET['rating'])) {
$result = rate($_GET['rating'], $db);
}
$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>
if(isset($_GET['rating'])) {
$result = rate($_GET['rating'], $_GET['id'], $db);
}
.
.
.
.
<li><a href="?rating=<?php echo $i ?>&id=<?php echo $row['id']; ?>" class="active" title="<?php echo $i ?> Star"><?php echo $i ?></a></li>
<?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>