Forum Moderators: coopster
//include our db data to make the connection
include ('db.php');
$content = mysql_query("SELECT * FROM cars ORDER BY id DESC");
while($row = mysql_fetch_assoc($content))
{
$mainImage = $row['mainImage'];
$oid = $row['oid'];
$thumbImage = $row['thumbImage'];
$car_username = $row['username'];
$username = $_SESSION['username'];
$date = $row['date'];
echo '<div class="gallimg"';
echo '<a href="'.$mainImage.'" name="'.$oid.'" rel="lightbox[cars]"><img src="'.$thumbImage.'" title="'.$car_username.'s car"/></a><br />';
echo 'by <span class="fat">'.$car_username.'</span> on '.$date.'<br />';
//get the votes for each image
$content2 = mysql_query("SELECT * FROM votes WHERE oid = '$oid' AND username = '$username'");
while($row2 = mysql_fetch_array($content2))
{
$voter = $row2['username'];
$vote = $row2['vote'];
}
//if the user has voted for an image
if (strlen($voter) > 1) {
//show the average vote
$content3 = mysql_query("SELECT SUM(vote) FROM votes WHERE oid = '$oid'");
while($row3 = mysql_fetch_array($content3))
{
$totalVotes = $row3['SUM(vote)'];
}
$content4 = mysql_query("SELECT * FROM votes WHERE oid = '$oid'");
$numbVoters = mysql_affected_rows();
if (strlen($totalVotes) > 0 && strlen($numbVoters) > 0) {
echo 'Rating: <span class="fat">' . $totalVotes / $numbVoters . '</span> Votes: ' . $numbVoters;
}
} else {
//show the vote box, and for testing purposes display the words: no vote
echo 'no vote';
}
echo "</div>";
}
echo '<div class="gallimg">';
if (strlen($totalVotes) > 0 && strlen($numbVoters) > 0)
if ($totalVotes > 0 && $numbVoters > 0)