jj72ny Posted July 20, 2013 Share Posted July 20, 2013 I am playing around with this script and can't figure out how to show just the results on a page Micro Rate Micro Rate Link to comment Share on other sites More sharing options...
niche Posted July 20, 2013 Share Posted July 20, 2013 Please post the relevant part of your script using the code tags. Link to comment Share on other sites More sharing options...
jj72ny Posted July 20, 2013 Author Share Posted July 20, 2013 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 More sharing options...
niche Posted July 20, 2013 Share Posted July 20, 2013 What's not showing? Link to comment Share on other sites More sharing options...
jj72ny Posted July 21, 2013 Author Share Posted July 21, 2013 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 More sharing options...
niche Posted July 21, 2013 Share Posted July 21, 2013 So, you want to display the current rating of something? Link to comment Share on other sites More sharing options...
jj72ny Posted July 21, 2013 Author Share Posted July 21, 2013 Yes Link to comment Share on other sites More sharing options...
niche Posted July 21, 2013 Share Posted July 21, 2013 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 More sharing options...
jj72ny Posted July 22, 2013 Author Share Posted July 22, 2013 Aparently I have misunderstood the concept of this blog I thought it was for help and to learn and learning is what I am trying to do so if its not to much to ask for you to explain your answer Link to comment Share on other sites More sharing options...
niche Posted July 22, 2013 Share Posted July 22, 2013 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 More sharing options...
jj72ny Posted July 23, 2013 Author Share Posted July 23, 2013 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 More sharing options...
justsomeguy Posted July 23, 2013 Share Posted July 23, 2013 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 More sharing options...
jj72ny Posted July 23, 2013 Author Share Posted July 23, 2013 Ok so file('ratings.txt');Because I believe that ratings.txt So this should open the file correct? Link to comment Share on other sites More sharing options...
jj72ny Posted July 23, 2013 Author Share Posted July 23, 2013 And to loop throughfor ($i=1; $i<=10; $i++)Where $i=1 is the times it should loop Not shore what the other numbers are I see them on w3 but really don't understand what they do Link to comment Share on other sites More sharing options...
justsomeguy Posted July 23, 2013 Share Posted July 23, 2013 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 More sharing options...
jj72ny Posted July 24, 2013 Author Share Posted July 24, 2013 IP address is correct it is supose to keep people from rating more than once Link to comment Share on other sites More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now