Parašė Gugiss· 2008 Lie. 16 19:07:01
#1
Tai va aš naudoju tokį įvertinimų skriptą ir aš noriu, kad įvertinimų vidurkį atvaizduotų kitam faile kaip tai padaryti?
<?php
/*************************************************
* Micro Rate
*
* Version: 1.0
* Date: 2007-07-17
*
****************************************************/
?>
<?php if ( (!isset($_POST['submit'])) ) { ?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<table width="100%">
<tr><td>Tavo balas:</td><td><select name="rate">
<?php for ($i = 1; $i <= 10; $i++) { echo "<option value=\"$i\">$i</option>"; } ?>
</select></td></tr>
<tr><td colspan="2" align="center"><input type="submit" value="Vertinti" name="submit"/></td></tr>
</table>
</form>
<?php } else {
$rate = isset ($_POST['rate']) ? $_POST['rate'] : 0;
$filename = "ratings";
$alreadyRated = false;
$totalRates = 0;
$totalPoints = 0;
$ip = getenv('REMOTE_ADDR');
$oldResults = file('results/'.$filename.'.txt');
foreach ($oldResults as $value) {
$oneRate = explode(':',$value);
if ($ip == $oneRate[0]) $alreadyRated = true;
$totalRates++;
$totalPoints += $oneRate[1];
}
if ((!$alreadyRated) && ($rate > 0)){
$f = fopen('results/'.$filename.".txt","a+");
fwrite($f,$ip.':'.$rate."\n");
fclose($f);
$totalRates++;
$totalPoints+=$rate;
}
?>
<div id="result">
<?php
echo "<font size='36'>".substr(($totalPoints/$totalRates),0,3)."</font><br/>";
for ($i=0;$i<round(($totalPoints/$totalRates),0);$i++){
echo "<img src='style/star.png' alt='s' />";
}
echo "</div>";
} ?>
</body>
O čia tas pimpalas kuris atvaizduoja tą vidurkį:
".substr(($totalPoints/$totalRates),0,3)."
Redagavo Gugiss· 2008 Lie. 16 19:07:14