How to create a basic rating system



by Administrator author list

 


"DTD/xhtml1-transitional.dtd">


if ( (!isset($_POST['submit'])) ) { ?>
echo $_SERVER['PHP_SELF']; ?>" method="post">







Your rating: 1 2 3 4 5





} else {
$rate = isset ($_POST['rate']) ? $_POST['rate'] : 0;
$filename = "ratings";
$alreadyRated = false;
$totalRates = 0;
$totalPoints = 0;

$ip = getenv('REMOTE_ADDR');

// Read the result file
$oldResults = file('results/'.$filename.'.txt');

// Summarize total points and rates
foreach ($oldResults as $value) {
$oneRate = explode(':',$value);
// If our IP is in the list then set the falg
if ($ip == $oneRate[0]) $alreadyRated = true;
$totalRates++;
$totalPoints += $oneRate[1];
}

// If our rating is valid then append it to the result file
if ((!$alreadyRated) && ($rate > 0)){
$f = fopen('results/'.$filename.".txt","a+");
fwrite($f,$ip.':'.$rate."\n");
fclose($f);
$totalRates++;
$totalPoints+=$rate;
}

echo
"Actual rating from $totalRates rates is: "
.substr(($totalPoints/$totalRates),0,3)."
"
;

// Display the actual rating
for ($i=0;$i<round(($totalPoints/$totalRates),0);$i++){
echo
"";
}
}
?>



article index
page 1 : untitled page
page 2 - current : Complete code


Tags: php rating system, file based rating, rating system file, rating system

Php Toys - 2006 - Php resources, scripts and tutorials - Privacy Policy
Insurance Index - Tutorial collection - Forex trading, brokers, reviews - Mortgage payment calculator
{THEMEDISCLAIMER}
Render time: 0.1290 sec, 0.0199 of that for queries. DB queries: 25.