ok i have this script but need to make changes to it in order for it to work the way i need it.
First thing is this : To put the rating stars on a page all i would do is add this on the page along with an include to the script on the page, which works fine.
<?ShowStars($subcatid);?>
BUt how would I add that inside of this for it to work...
echo "<td align=\"right\">RIGHT HERE IS WHERE I WANT STARS <br>";
Now i tried so many different ways. I just cant get anything to work and I think it is because I am trying to put it in an echo or something.
Also I cant figure out what these mean.
$days = 1;
$m = 20;
$C = 6;
Once i get this figured out i will post other issue
I would ask the guy who wrote this, but he can no longer be found.
$days = 1;
$m = 20;
$C = 6;
@mysql_connect("localhost",$username,$password);
@mysql_select_db($database);
if($_POST['action'] == "doit")
{
if($_POST['rates']>0 && $_POST['rates']<11 && !empty($_POST['rateit_id']))
{
$ip = getenv("REMOTE_ADDR");
$query = "SELECT count(*) AS num FROM ratings WHERE (datum>SUBDATE(CURRENT_DATE(),INTERVAL ".$GLOBALS['days']." DAY) AND ip='$ip' AND article='".$_POST['rateit_id']."')";
$rs = mysql_query($query) or die("LINE 17:".mysql_error());
$as = mysql_fetch_array($rs);
if($as[num]==0)
mysql_query("INSERT INTO ratings VALUES(0,'".$_POST['rateit_id']."','".$_POST['rates']."','".$ip."',NOW())") or die(mysql_error());
//echo $as[num];
}
}
function ShowForm($id,$num,$rate_me="Rate Me",$rate_it="Rate!",$class="")
{
echo '<form action="'.$SCRIPT_NAME.'" method="post">';
echo '<select name="rates" class="'.$class.'">';
echo '<option value="x" selected>'.$rate_me.'</option>';
for($x=$num;$x>0;$x--)
echo '<option value="'.$x.'">'.$x.'</option>';
echo '</select>';
echo '<input type="hidden" name="rateit_id" value="'.$id.'">';
echo '<input type="hidden" name="action" value="doit"> ';
echo ' <input type="submit" value="'.$rate_it.'" class="'.$class.'">';
echo '</form>';
}
function NumRates($id)
{
$res = mysql_query("SELECT count(*) AS num FROM ratings WHERE article='".$id."'") or die("LINE 50:".mysql_error());
$ar = mysql_fetch_array($res);
if(empty($ar[num])) $ar[num] = "0";
return $ar[num];
}
function ShowResult($id)
{
/*
The formula for calculating the top 250 films gives a true Bayesian estimate:
weighted rank (WR) = (v ÷ (v+m)) × R + (m ÷ (v+m)) × C
where:
R = average for the item(mean) = (Rating)
v = number of votes for the item= (votes)
m = minimum votes required to be listed in the top 250 (currently 1250)
C = the mean vote across the whole report (currently 6.9)
*/
$query = "SELECT COUNT(*) as num, ((COUNT(*)/(COUNT(*)+".$GLOBALS['m']."))*AVG(rate)+(".$GLOBALS['m']."/(COUNT(*)+".$GLOBALS['m']."))*".$GLOBALS['C'].") AS rate FROM ".$GLOBALS['table']." WHERE rate>0 AND rate<11 AND article=".$id;
$res = mysql_query($query) or die("<b>LINE 74</b>:".mysql_error());
$ar = mysql_fetch_array($res);
$procent = $ar[rate];
if(empty($procent) || $procent<0) $procent=0;
echo $procent;
}
function ShowStars($id,$width=20)
{
$query = "SELECT COUNT(*) as num, ((COUNT(*)/(COUNT(*)+".$GLOBALS['m']."))*AVG(rate)+(".$GLOBALS['m']."/(COUNT(*)+".$GLOBALS['m']."))*".$GLOBALS['C'].") AS rate FROM ".$GLOBALS['table']." WHERE rate>0 AND rate<11 AND article=".$id;
$res = mysql_query($query) or die("<b>LINE 85</b>:".mysql_error());
$ar = mysql_fetch_array($res);
$procent = (int) $ar[rate]+0.5;
if(empty($procent) || $procent<0) $procent=0;
for($x=1;$x<=$procent;$x++)
echo '<img src="./gfx/star1.jpg" alt="" width="'.$width.'"/>';
$io = $ar[rate] - (int)$ar[rate];
if($io>0.49) echo '<img src="./gfx/star2.jpg" alt="" width="'.$width.'"/>';
}