Page 1 of 1

Showing data you got on one page on another page

Posted: Mon Jul 01, 2002 11:22 am
by killkenny
I've made a script for rating downloads, when people open a certain page they are able to rate the download and they get an average rating after they vote. Now i want to put up all the averages on another page to show them. How can i do this with the following script:
The main File:

Code: Select all

<?			
if($blah)
&#123;
include "rating.dat";

$p=0;
$aantal=sizeof($cijfertjes);
for($x=0;$x<$aantal;$x++)
&#123;
$p+=$cijfertjes&#1111;$x];
&#125;
$gem = $p/$aantal;
echo "<b>Rating:</b> $gem";
&#125;
else
&#123;
?>
<br>
<FORM action="vote.php">
<select name="vote" onchange="this.form.submit()">
<option>Rate this download...
<option value=1>1
 <option value=2>2
 <option value=3>3
 <option value=4>4
 <option value=5>5
 <option value=6>6
 <option value=7>7
 <option value=8>8
 <option value=9>9
 <option value=10>10
 </select>
 </form>
<?
&#125;
?>
And the vote.php file:

Code: Select all

<?
$fp=fopen("rating.dat",a);
fputs($fp,
"<? \$cijfertjes&#1111;]=$vote; ?>");
fclose($fp);
echo "Thanks for voting!
<meta http-equiv="refresh" content="1; url=main.php?blah=ok">";
?>
And all the votings go into a file, in the above script that is rating.dat. But for other ratings there are other *.dat files to contain the data of that rating.
And i want to put the averages ($gem variable) of more than one rating on one page. How can i do this??

Posted: Mon Jul 01, 2002 12:22 pm
by RandomEngy
I'm just going to point out some things you have in your code that might give you headaches later on:

Why variable names like cijfertjes, aantal and gem? That's completely confusing for anyone looking at your code, and yourself if it gets too complex. How about vote_array, array_size and avg_rating?

Use the [syntax=php][/syntax] tags when putting your PHP script up, it saves the formatting.

$fp=fopen("rating.dat",a); should be $fp=fopen("rating.dat","a");

Posted: Tue Jul 02, 2002 3:39 am
by killkenny
Sorry, i forgot about the code tags.
Why variable names like cijfertjes, aantal and gem? That's completely confusing for anyone looking at your code, and yourself if it gets too complex. How about vote_array, array_size and avg_rating?
The variable names are the dutch words for what it does, i know it might be confusing for other people, but for me it's easier to look at. For the other people, here is a translation of the words:
cijfertjes: The rating that was given.
aantal: The number of times people voted
gem: The average rating

Hopefully this will help