Jump to content

Show just results on a page


jj72ny
 Share

Recommended Posts

lol thought i did

<?php/************************************************* * Micro Rate * * Version: 1.0 * Date: 2007-07-17 * ****************************************************/

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "DTD/xhtml1-transitional.dtd"><html><head> <title>Micro Rate</title> <link href="style/style.css" rel="stylesheet" type="text/css" /></head><body> <div id="main"> <div id="caption">Micro Rate</div> <div id="icon"> </div> <?php if ( (!isset($_POST['submit'])) ) { ?> <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"> <table width="100%"> <tr><td>Your rating:</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="Rate it!" 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 "Actual rating from $totalRates rates is: ".substr(($totalPoints/$totalRates),0,3)."<br/>"; for ($i=0;$i<round(($totalPoints/$totalRates),0);$i++){ echo "<img src='style/star.png' alt='s' />"; }echo "</div>"; } ?> <div id="source">Micro Rate 1.0</div> </div>

Link to comment
Share on other sites

When I open my page I want to put this on instead of it going to the pull down then submit I would like it to go directly to the result page and a button to take you to the rate button Ie Open a book title page and see what other people have rated it then if you have read the book you also can rate it then see the results

Link to comment
Share on other sites

Query your DB, load the results into a variable, display your var. What part of that is the trouble?

Link to comment
Share on other sites

I still don't know where the problem is. There's three steps per #8. Which step is you the problem? For starters, how do you know you're working with the right results?

Link to comment
Share on other sites

After some research I found out that this dose not go through a data base info is saved in a txt file witch I have been trying to figure out it still can't be that hard it's right there in the php I just don't know what line or lines it is the program dose it just need to reverse it

Link to comment
Share on other sites

It reads the file contents using the file function, has a loop where it goes through the file and counts everything, and then an if statement where it writes information back to the file if it needs do. Like you said, there's not a lot of code there, look for the file function.

Link to comment
Share on other sites

 

 

So this should open the file correct?

That's going to return the lines of the file in an array.

 

http://www.php.net/manual/en/function.file.php

 

 

And to loop throughfor ($i=1; $i<=10; $i++)Where $i=1 is the times it should loop

No, that's not how a for loop works. There's a description of for loops here, run some of the examples if you want to see what they do:

 

http://www.php.net/manual/en/control-structures.for.php

 

You can either use a for loop, or a foreach loop. Your original code uses foreach to loop through the file and process each line. It looks like each line in the file has an IP address and rating.

 

http://www.php.net/manual/en/control-structures.foreach.php

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

×
×
  • Create New...