Code:
Code: Select all
<?php
if (!file_exists("rate.txt"))
{
$file=fopen("rate.txt", "w");
for ($i=0;$i<1000;$i+=1) {
$newline+="0^^0||";
}
fputs($file,$newline);
fclose ($file);
}
else {
$filename = "rate.txt";
}
$filename = "rate.txt";
$content = file("rate.txt");
//put content in array
$array = explode("||", $content[0]);
for ($i=0;$i<1000;$i+=1) {
$miniarray[$i] = explode("^^", $array[$i]);
}
$miniarray[$showtopic][0] += 1;
$miniarray[$showtopic][1] += $rating;
$array[$showtopic] = $miniarray[$showtopic][0]."^^".$miniarray[$showtopic][1];
$fp = fopen($filename,"w");
insert votes to txt file
for ($i=0;$i<1000;$i+=1) {
$insertvote += $array[$showtopic]."||";
}
fwrite($fp,$insertvote);
//fclose($fp);
echo "Total votes: ".$miniarray[$showtopic][0];
echo " Rating: ".$miniarray[$showtopic][1]/$miniarray[$showtopic][0];
?>What it's supposed to do is check if there is a file, if not, make a new one with 1000 sets of "0^^0||" inside the file. Then I use an explode function to make an array with each value of the array displaying something that should look like this: "0^^0". Then I do another explode, 1000 times something such as "0". Now depending on what the person put in the url for $showtopic and $rating, it adds to miniarray[$showtopic][0] and miniarray[showtopic][1]. After this it is supposed to write the arrays back into the file, with the "updates". Then show the rating and number of votes on the page.
It doesn't work... It doesn't save the values into the file.
If I didn't lose you there... Is there anyone who can help me with this? Any help would be appreciated.