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.
Page 1 of 3 123 LastLast
Results 1 to 15 of 36

Thread: 5 Star Rater

  1. #1
    Banned
    Join Date
    Aug 2007
    Posts
    113
    Thanks
    22
    Thanked 0 Times in 0 Posts

    5 Star Rater

    How do I make a 5 Rating System to rate videos, pictures, etc. on my site?

  • #2
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    I actually have one that I modified to do 10, but if you know php well enough you should beable to modify and understand the script. Then all you need is 5 "star images". well let me know if youd like the code and ill post it for ya

  • Users who have thanked wayne3503 for this post:

    afesoccer (08-24-2007)

  • #3
    Banned
    Join Date
    Aug 2007
    Posts
    113
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Yes please, I would like the code. Thank you.

  • #4
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Here you go. You will see the images or "stars" I used are called spots. But all you need to do is figure what you want to use for your stars and then name the files and change the code.
    PHP Code:
    <?
    // User settings
    $rater_ip_voting_restriction true// restrict ip address voting (true or false)
    $rater_ip_vote_qty=1// how many times an ip address can vote
    $rater_already_rated_msg="You have already rated this item. You are allowed only ".$rater_ip_vote_qty." vote.";
    $rater_not_selected_msg="You have not selected a rating value.";
    $rater_thankyou_msg="Thankyou for voting.";
    $rater_generic_text="this place"// generic item text
    $rater_end_of_line_char="n"// may want to change for different operating systems


    if(!isset($rater_id)) $rater_id=1;
    if(!isset(
    $rater_item_name)) $rater_item_name=$rater_generic_text;


    // DO NOT MODIFY BELOW THIS LINE
    $rater_filename='item_'.$rater_id.".rating";
    $rater_rating=0;
    $rater_stars="";
    $rater_stars_txt="";
    $rater_rating=0;
    $rater_votes=0;
    $rater_msg="";

    // Rating action
    if(isset($_REQUEST["rate".$rater_id])){
     if(isset(
    $_REQUEST["rating_".$rater_id])){
      while(list(
    $key,$val)=each($_REQUEST["rating_".$rater_id])){
       
    $rater_rating=$val;
      }
      
    $rater_ip getenv("REMOTE_ADDR"); 
      
    $rater_file=fopen($rater_filename,"a+");
      
    $rater_str="";
      
    $rater_str rtrim(fread($rater_file1024*8),$rater_end_of_line_char);
      if(
    $rater_str!=""){
       if(
    $rater_ip_voting_restriction){
        
    $rater_data=explode($rater_end_of_line_char,$rater_str);
        
    $rater_ip_vote_count=0;
        foreach(
    $rater_data as $d){
         
    $rater_tmp=explode("|",$d);
         
    $rater_oldip=str_replace($rater_end_of_line_char,"",$rater_tmp[1]);
         if(
    $rater_ip==$rater_oldip){
          
    $rater_ip_vote_count++;
         }
        }
        if(
    $rater_ip_vote_count > ($rater_ip_vote_qty 1)){
         
    $rater_msg=$rater_already_rated_msg;
        }else{
         
    fwrite($rater_file,$rater_rating."|".$rater_ip.$rater_end_of_line_char);
         
    $rater_msg=$rater_thankyou_msg;
        }
       }else{
        
    fwrite($rater_file,$rater_rating."|".$rater_ip.$rater_end_of_line_char);
        
    $rater_msg=$rater_thankyou_msg;
       }
      }else{
       
    fwrite($rater_file,$rater_rating."|".$rater_ip.$rater_end_of_line_char);
       
    $rater_msg=$rater_thankyou_msg;
      }
      
    fclose($rater_file);
     }else{
      
    $rater_msg=$rater_not_selected_msg;
     }
    }

    // Get current rating
    if(is_file($rater_filename)){
     
    $rater_file=fopen($rater_filename,"r");
     
    $rater_str="";
     
    $rater_str fread($rater_file1024*8);
     if(
    $rater_str!=""){
      
    $rater_data=explode($rater_end_of_line_char,$rater_str);
      
    $rater_votes=count($rater_data)-1;
      
    $rater_sum=0;
      foreach(
    $rater_data as $d){
       
    $d=explode("|",$d);
       
    $rater_sum+=$d[0];
      }
      
    $rater_rating=number_format(($rater_sum/$rater_votes), 2'.''');
     }
     
    fclose($rater_file);
    }else{
     
    $rater_file=fopen($rater_filename,"w");
     
    fclose($rater_file);
    }

    // Assign star image
    if ($rater_rating <= 0){$rater_stars "./img/0spot.gif";$rater_stars_txt="Not Rated";}
    if (
    $rater_rating >= 1){$rater_stars "./img/1spot.gif";$rater_stars_txt="1";}
    if (
    $rater_rating >= 2){$rater_stars "./img/2spot.gif";$rater_stars_txt="2";}
    if (
    $rater_rating >= 3){$rater_stars "./img/3spot.gif";$rater_stars_txt="3";}
    if (
    $rater_rating >= 4){$rater_stars "./img/4spot.gif";$rater_stars_txt="4";}
    if (
    $rater_rating >= 5){$rater_stars "./img/5spot.gif";$rater_stars_txt="5";}
    if (
    $rater_rating >= 6){$rater_stars "./img/6spot.gif";$rater_stars_txt="6";}
    if (
    $rater_rating >= 7){$rater_stars "./img/7spot.gif";$rater_stars_txt="7";}
    if (
    $rater_rating >= 8){$rater_stars "./img/8spot.gif";$rater_stars_txt="8";}
    if (
    $rater_rating >= 9){$rater_stars "./img/9spot.gif";$rater_stars_txt="9";}
    if (
    $rater_rating >= 10){$rater_stars "./img/10spot.gif";$rater_stars_txt="10";}

    // Output
    echo '<div class="hreview">';
    echo 
    '<form method="post" action="'.$_SERVER["PHP_SELF"].'">';
    echo 
    '<h3 class="item">Rate <span class="fn">'.$rater_item_name.'</span></h3>';
    echo 
    '<div>';
    echo 
    '<span  class="rating"><img src="'.$rater_stars.'?x='.uniqid((double)microtime()*1000000,1).'" alt="'.$rater_stars_txt.' spot" /> Average rating</span>.';
    echo 
    '</div>';
    echo 
    '<div>';
    echo 
    '<label for="rate1_'.$rater_id.'"><input type="radio" value="1" name="rating_'.$rater_id.'[]" id="rate1_'.$rater_id.'" />Worst Ever</label></br>';
    echo 
    '<label for="rate2_'.$rater_id.'"><input type="radio" value="2" name="rating_'.$rater_id.'[]" id="rate2_'.$rater_id.'" />Poor</label></br>';
    echo 
    '<label for="rate3_'.$rater_id.'"><input type="radio" value="3" name="rating_'.$rater_id.'[]" id="rate3_'.$rater_id.'" />Ok</label></br>';
    echo 
    '<label for="rate4_'.$rater_id.'"><input type="radio" value="4" name="rating_'.$rater_id.'[]" id="rate4_'.$rater_id.'" />Not to Bad</label></br>';
    echo 
    '<label for="rate5_'.$rater_id.'"><input type="radio" value="5" name="rating_'.$rater_id.'[]" id="rate5_'.$rater_id.'" />Good</label></br>';
    echo 
    '<label for="rate6_'.$rater_id.'"><input type="radio" value="6" name="rating_'.$rater_id.'[]" id="rate6_'.$rater_id.'" />Very Good</label></br>';
    echo 
    '<label for="rate7_'.$rater_id.'"><input type="radio" value="7" name="rating_'.$rater_id.'[]" id="rate7_'.$rater_id.'" />Excellent</label></br>';
    echo 
    '<label for="rate8_'.$rater_id.'"><input type="radio" value="8" name="rating_'.$rater_id.'[]" id="rate8_'.$rater_id.'" />Amazing</label></br>';
    echo 
    '<label for="rate9_'.$rater_id.'"><input type="radio" value="9" name="rating_'.$rater_id.'[]" id="rate9_'.$rater_id.'" />Best Ever</label></br>';
    echo 
    '<label for="rate10_'.$rater_id.'"><input type="radio" value="10" name="rating_'.$rater_id.'[]" id="rate10_'.$rater_id.'" />HOTT</label></br>';
    echo 
    '<input type="hidden" name="rs_id" value="'.$rater_id.'" />';
    echo 
    '<input type="submit" name="rate'.$rater_id.'" value="Rate" />';
    echo 
    '</div>';
    if(
    $rater_msg!="") echo "<div>".$rater_msg."</div>";
    echo 
    '</form>';
    echo 
    '</div>';

    ?>
    Have fun

  • #5
    Banned
    Join Date
    Aug 2007
    Posts
    113
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Ohh I see. Where do I put this code?

  • #6
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    just save it as its own script somewhere then just do an include then have it do an echo or something. I havent played with it a whole lot as I have had bigger fish to fry with my project... so you will have to play with it a little bit to get it just as you like. But what will happen is you fill out the form and place a rating then hit the submit button and it will get echoed. But even better, it will echo out the "average" rating which is really nice.
    Good luck
    keep me posted with how your doing.

  • #7
    Banned
    Join Date
    Aug 2007
    Posts
    113
    Thanks
    22
    Thanked 0 Times in 0 Posts
    Ok I saved as rater.php. Is that what I was suppose to do? How do I do the include?

  • #8
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    PHP Code:
    <?php
    include('rater.php'); // change the path if it is in a different directory
    ?>

  • #9
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    The script has a form built in so you will have to incorporate everything how youd like it to be.

  • #10
    Banned
    Join Date
    Aug 2007
    Posts
    113
    Thanks
    22
    Thanked 0 Times in 0 Posts
    <?php
    include('rater.php'); // change the path if it is in a different directory
    ?> Do I put that in the page where the video is?

  • #11
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Yes, I would think so. And your file will have to be named .php or at least parsed by PHP.

  • #12
    Regular Coder
    Join Date
    Jul 2007
    Posts
    108
    Thanks
    0
    Thanked 2 Times in 2 Posts
    put that at the top of the page you want to include it in. but you dont need the <?php ?> tags if you already have them in your video script

  • #13
    Banned
    Join Date
    Aug 2007
    Posts
    113
    Thanks
    22
    Thanked 0 Times in 0 Posts
    http://www.afesoccer.com/rater.html That's where I put the <?php
    include('rater.php'); // change the path if it is in a different directory
    ?>

    The rater.php I uploaded to www.afesoccer.com/rater.php. But there is nothing on www.afesoccer.com/rater.html.

  • #14
    Super Moderator Inigoesdr's Avatar
    Join Date
    Mar 2007
    Location
    Florida, USA
    Posts
    3,647
    Thanks
    2
    Thanked 406 Times in 398 Posts
    Quote Originally Posted by Inigoesdr View Post
    And your file will have to be named .php or at least parsed by PHP.

  • #15
    Banned
    Join Date
    Aug 2007
    Posts
    113
    Thanks
    22
    Thanked 0 Times in 0 Posts
    I don't understand.


  •  
    Page 1 of 3 123 LastLast

    Posting Permissions

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