Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Rating system

  1. #1
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts

    Rating system

    Hi, I am having soo much trouble trying to find a simple rating system tutorial or script.

    Can anyone help me out here?

    I want the data to be stored in a mysql database, in a row called score.
    When a user clicks an option (1 to 5) it gets the number from the database (say 4.24) then does some maths and puts the data back in (say 4.57) depending on what number they clicked and how many votes there are.

    If possible:
    Ajax (no reloading the page)
    0.00 (2 decimal places)

    Thanks for you help

  • #2
    Regular Coder
    Join Date
    Feb 2008
    Location
    Australia baby!
    Posts
    143
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Check out http://www.dhtmlgoodies.com/index.ht...pt=ajax-poller

    Looks pretty nice, just as you asked I believe. See it live at outer reaches (for a little while)
    outseeker - http://outer.reaches.dyndns.org/index.php
    I hope this helped someone. Due to this forums lame rep system penalising me for nothing, and admins inability to do anything about it, I'm sorry to say I will no longer be online here. Pride is important. Good Luck All.

  • #3
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    Thanks but I cannot get the script to work...

  • #4
    Regular Coder
    Join Date
    Feb 2008
    Location
    Australia baby!
    Posts
    143
    Thanks
    6
    Thanked 3 Times in 3 Posts
    lol we have another thread already happening to sort that one out. Basically, edit your .php files to have the correct MySQL login name, password and database. Then run the table install php file. Rename their .html example they give you to .php and it should work just fine. Here's the other post: http://www.codingforums.com/showthread.php?t=133408

    Cheers.
    outseeker - http://outer.reaches.dyndns.org/index.php
    I hope this helped someone. Due to this forums lame rep system penalising me for nothing, and admins inability to do anything about it, I'm sorry to say I will no longer be online here. Pride is important. Good Luck All.

  • #5
    Regular Coder Ludatha's Avatar
    Join Date
    Jan 2008
    Posts
    250
    Thanks
    51
    Thanked 5 Times in 5 Posts
    I've been fiddling around with this script, I'm trying to get it to use the database instead of a text file.

    PHP Code:
    if ( (!isset($_POST['scoresubmit'])) ) { ?>
            <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="scoresubmit"/></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 "Total score from $totalRates votes 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>";       
           }
                
                
                
                
                
                
                echo 
    '
                </td>
      </tr>
      <tr>
        <td colspan="4">
                </td>
      </tr>

    </table>'
    ;
    Any ideas?

  • #6
    Regular Coder
    Join Date
    Feb 2008
    Location
    Australia baby!
    Posts
    143
    Thanks
    6
    Thanked 3 Times in 3 Posts
    Hmm well I grabbed the code, added the relevant <?php etc's to make it run, but I've never used php and html together the way they do here! Closing and reopening php while just inserting plain html in between seems very weird structure to me. Dunno where to begin mate. Actually I do I think. Instead of closing the php off and inserting plain html, do this:

    echo "<html here>";

    Then at least I will be able to understand and work with it

    For example the first lines mate, make it like this:

    if ( (!isset($_POST['scoresubmit'])) ) {
    echo "<form action=\"".$_SERVER['PHP_SELF']. "\" method=\"post\"><table width=\"100&#37;\"><tr><td>Your rating:</td><td><select name=\"rate\">";


    So u always stay in PHP, and tell it to echo any html you need. If you wanna use $variables, just do like I've done and close off the " and use a .$whatever. then open the talking marks back up. You will notice the \"'s too. When you echo, the talking marks inside the echo must be backslashed unless you are temporarily stopping the echo to add a $variable or something.

    I'm not extremely well versed in PHP but I hope this is of some use to you. Try rewriting it to not close off PHP with ?> etc and re-post if you wouldn't mind.
    Last edited by outseeker; 02-19-2008 at 01:33 AM.
    outseeker - http://outer.reaches.dyndns.org/index.php
    I hope this helped someone. Due to this forums lame rep system penalising me for nothing, and admins inability to do anything about it, I'm sorry to say I will no longer be online here. Pride is important. Good Luck All.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •