I am sending
Code: Select all
<?=NumRates(100);?> , <?ShowResult(100);?>, <?ShowStars(100);?>But as I have different sections (article,news etc. and each has similar id) so i want to send article1,article2 from article page... news1,news2 from news page (rather than only the id i am using the name of the section to store/identify a particular data)
If i write
Code: Select all
<?ShowResult(article12);?>How o correct this
Code: Select all
function ShowForm($id,$num,$rate_me="Rate Me",$rate_it="Rate!",$class="")
{
echo '<form action="'.$GLOBALS['PHP_SELF'].'" 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 movie (mean) = (Rating)
v = number of votes for the movie = (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.'"/>';
}