Rating script
Posted: Wed Jan 21, 2004 6:03 pm
I've found this rating script, but theres an error somewhere that I cant find because lack of php knowledge 
anyway, heres the code
The problem is that when I choose the rating from the dropdown box nothing happens. Seems like it won't communicate with the database or something... Can anyone help me please ?
thanks..
anyway, heres the code
Code: Select all
<?php require_once('settings.php'); ?>
<?php
$connection = mysql_connect($hostname , $username , $password) or die ("Could not connect to database");
mysql_select_db ($database , $connection) or die ("Could not find database")
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<link href="stylesheet.css" rel="stylesheet" type="text/css">
</head>
<body>
<table align="center" width="800" class="newsborder" border="0" cellspacing="0" cellpadding="0">
<tr>
<td align="center" class="logo"><?php echo $sitename ?></td>
</tr>
<tr>
<td colspan="2" height="35"><table width="100%" border="0" cellpadding="5" cellspacing="0">
<tr>
<td valign="top"><table width="100%" class="newsborder" border="0" cellpadding="5" cellspacing="0">
<tr>
<th>| <a href="index.php">Home</a> | <img src="images/arrow.gif" width="10" height="11">Gallery | <a href="admin/admin.php">Admin</a> | </th>
</tr>
</table></td>
</tr>
<tr>
<td align="center" valign="top">
<?php
/*Next-Previous Settings*/
if(!isset($start)) $start = 0;
$next=$start + $end;
$prev=$start - $end;
$end=1;
$category_query = "SELECT * FROM gallery ORDER BY gallery_id DESC LIMIT ".$start.", ".$end."";
$query_result = mysql_query ($category_query, $connection);
$num_rows = mysql_num_rows($query_result);
while ($row = mysql_fetch_object ($query_result))
{
echo "<table>";
echo "<tr><td>";
echo "<img src="" . $row->gallery_url . "" . $row->gallery_file . "?x=" . uniqid((double)microtime()*1000000,1) ."">";
echo "</td></tr>";
echo "</table>";
}
//second script added for navigation
$category_query = "SELECT count(*) FROM gallery";
$query_result = mysql_query($category_query , $connection) or die("SELECT Error: [$category_query]".mysql_error());
$num_rows = array_shift(mysql_fetch_row($query_result));
if($start > 0)
{
echo '| <a href="', $PHP_SELF, '?start='.($prev - $end). '&id=' .$id. '">Previous</a> |';
}
if($num_rows > ($start + $end))
{
echo '| <a href="'. $PHP_SELF .'?start=' .($start + $end). '&id=' .$id. '">Next</a> |';
}
/////////////////////////////////////////////////////////////////////////////////////
//Ratemenu
function ratemenu($gallery_id){
echo "<form name="rating" method="post" action="gallery.php">
<font class="subfont">Rate this Strip:</font>
<select name="rating">
<option value="5.0" selected>5 - Excellent!</option>
<option value="4.0">4</option>
<option value="3.0">3 - Fair</option>
<option value="2.0">2</option>
<option value="1.0">1 - Poor</option>
<option value="0.0">0 - Awful!</option>
<input type="hidden" name="cmd" value="do_rating">
<input type="hidden" name="gallery_id" value="$gallery_id">
<input type="submit" value="Go!">
</select>
</form>";
}
//Adding ratingvalues from menu
function do_rating($gallery_id, $rating){
if (session_is_registered("rating$gallery_id")){
echo "<center>Sorry! You have already voted!";
} else {
$get_count = mysql_query("SELECT gallery_rating, gallery_num_votes FROM gallery WHERE (gallery_id = '$gallery_id')");
while(list($gallery_rating, $gallery_num_votes)=mysql_fetch_array($get_count)){
$new_count = ($gallery_num_votes + 1);
$gallery_rating2 = ($gallery_rating * $gallery_num_votes);
$new_rating = (($rating + $gallery_rating2) / ($new_count));
$new_rating2 = number_format($new_rating, 2, '.', '');
$update_rating = mysql_query("UPDATE gallery SET{gallery_rating, gallery_num_votes) VALUES('$new_rating2','$new_count') WHERE(gallery_id = '$gallery_id')");
$sessionvar = "gallery$gallery_id";
session_register($sessionvar);
echo "<div align="center"><b>
<p>Thanks for your vote!</p>
<p>The new rating for this strip is:
$new_rating2 out of 5</p>";
}
}
echo "<p align="center"><a href="javascript:history.back();"><<
Back</a> | <a href="/index.php">Main Page</a> | <a href="gallery.php">Gallery Index>></a></b>
</p>";
}
//Show the rating images
function gallery_stars($gallery_rating){
if((($gallery_rating >= 0)or($gallery_rating == 0)) && ($gallery_rating <= 0.50)){
echo "<img src="images/stars/0o5.gif" width="70" height="18">";
}
if((($gallery_rating >= 0.50)or($gallery_rating == 0.50)) && ($gallery_rating <= .99)){
echo "<img src="images/stars/05o5.gif" width="70" height="18">";
}
if((($gallery_rating >= 1.00)or($gallery_rating == 1.50)) && ($gallery_rating <= 1.49)){
echo "<img src="images/stars/1o5.gif" width="70" height="18">";
}
if((($gallery_rating >= 1.50)or($gallery_rating == 1.50)) && ($gallery_rating <= 1.99)){
echo "<img src="images/stars/15o5.gif" width="70" height="18">";
}
if((($gallery_rating >= 2.00)or($gallery_rating == 2.00)) && ($gallery_rating <= 2.49)){
echo "<img src="images/stars/2o5.gif" width="70" height="18">";
}
if((($gallery_rating >= 2.50)or($gallery_rating == 2.50)) && ($gallery_rating <= 2.99)){
echo "<img src="images/stars/25o5.gif" width="70" height="18">";
}
if((($gallery_rating >= 3.00)or($gallery_rating == 3.00)) && ($gallery_rating <= 3.49)){
echo "<img src="images/stars/3o5.gif" width="70" height="18">";
}
if((($gallery_rating >= 3.50)or($gallery_rating == 3.50)) && ($gallery_rating <= 3.99)){
echo "<img src="images/stars/35o5.gif" width="70" height="18">";
}
if((($gallery_rating >= 4.00)or($gallery_rating == 4.00)) && ($gallery_rating <= 4.49)){
echo "<img src="images/stars/4o5.gif" width="70" height="18">";
}
if((($gallery_rating >= 4.50)or($gallery_rating == 4.50)) && ($gallery_rating <= 4.99)){
echo "<img src="images/stars/45o5.gif" width="70" height="18">";
}
if($gallery_rating == 5.0){
echo "<img src="images/stars/5o5.gif" width="70" height="18">";
}
}
echo "".gallery_stars($gallery_rating)."";
echo "".ratemenu($gallery_id)."";
echo "".do_rating($gallery_id, $rating)."";
?>
</td>
</tr>
<tr>
<td height="10" align="center" valign="top" class="bar"><span class="style1"> Copyright © Lost In Space Team 2002,2003 </span></td>
</tr>
</table></td>
</tr>
</table>
</body>
</html>thanks..