Page 1 of 1

help improve thsi rating system!

Posted: Wed Jul 19, 2006 9:32 pm
by PHPnewbienumberx

Code: Select all

<?
 /******************************/
 /* rateit.php                 */
 /* author: gregor@klevze.si   */
 /* 23.Maj, 2003               */
 /* http://www.skintech.org    */
 /******************************/
 
 $username = "";
 $password = "";
 $database = "";
 $table    = "";

 $days     = 1;
 $m 	   = 20;
 $C        = 6;
 
 @mysql_pconnect("HOSTGOESHERE",$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 $ad[num];
  }
 }

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 '&nbsp;<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.'"/>';
}
?>
i want to make it so it's possible to distinguish between say test.php?id=1 and test.php?id=2
your help is appreciated

Posted: Wed Jul 19, 2006 9:44 pm
by Luke
the difference between test.php?id=1 and test.php?id=1 ??

That's going to be hard to find my friend.

Posted: Wed Jul 19, 2006 9:49 pm
by PHPnewbienumberx
ninjaedit!

Posted: Wed Jul 19, 2006 9:51 pm
by Luke
LOL ok that's better... let me take a look...

EDIT:

I don't see where test.php?id=1 is relevent... where is this in your code or where is it input?

Posted: Wed Jul 19, 2006 10:08 pm
by Benjamin
id would be in the $_GET[''] array not the $_POST[''] array just so you know.

I don't see $_GET['id'] or $_POST['id'] in that code anywhere either.

Posted: Wed Jul 19, 2006 10:36 pm
by PHPnewbienumberx
The Ninja Space Goat wrote:LOL ok that's better... let me take a look...

EDIT:

I don't see where test.php?id=1 is relevent... where is this in your code or where is it input?
well, i know i want to make it a hidden input, but i don't know what to make the value of the input, considering id=any number

Posted: Wed Jul 19, 2006 10:43 pm
by Benjamin
Can you please clarify your question? What exactly are you trying to do?

Posted: Wed Jul 19, 2006 10:47 pm
by PHPnewbienumberx
well, take a look here http://www.piranhaparty.com

i have a system set up, where each ID is a different page, and on that same page, the rating system is placed

the problem is, when someone votes, it submits it into my database only as details.php and doesn't take into account the id part. how would i get it to take into account the ID part and submit it into my database as details.php?id=1 instead of just details.php