Advanced Search

Results 1 to 7 of 7

Thread: Rating System

  1. #1
    Join Date
    May 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Rating System

    (Don't know if this is the right forum i've putted this post in?)

    Anybody how got a code for a rating system???

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    (Don't know if this is the right forum i've putted this post in?)
    No, you haven't.

    A rating system requires a server-side language to be installed and enabled on your server, since it must store data server-side.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Talking Rating System

    Quote Originally Posted by Twey
    No, you haven't.

    A rating system requires a server-side language to be installed and enabled on your server, since it must store data server-side.
    You have come to the right section... You can code a rating system in PHP.... You will need a database to store the information but the SYSTEM itself can be coded in php...

    Here is Something Like what I use:

    Put The Following Code into a php file:

    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 were allowed ".$rater_ip_vote_qty." vote(s).";
    $rater_not_selected_msg="You have not selected a rating value.";
    $rater_thankyou_msg="Thankyou for voting.";
    $rater_generic_text="this item"// 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 <= ){$rater_stars "./img/00star.gif";$rater_stars_txt="Not Rated";}
    if (
    $rater_rating >= 0.5){$rater_stars "./img/05star.gif";$rater_stars_txt="0.5";}
    if (
    $rater_rating >= ){$rater_stars "./img/1star.gif";$rater_stars_txt="1";}
    if (
    $rater_rating >= 1.5){$rater_stars "./img/15star.gif";$rater_stars_txt="1.5";}
    if (
    $rater_rating >= ){$rater_stars "./img/2star.gif";$rater_stars_txt="2";}
    if (
    $rater_rating >= 2.5){$rater_stars "./img/25star.gif";$rater_stars_txt="2.5";}
    if (
    $rater_rating >= ){$rater_stars "./img/3star.gif";$rater_stars_txt="3";}
    if (
    $rater_rating >= 3.5){$rater_stars "./img/35star.gif";$rater_stars_txt="3.5";}
    if (
    $rater_rating >= ){$rater_stars "./img/4star.gif";$rater_stars_txt="4";}
    if (
    $rater_rating >= 4.5){$rater_stars "./img/45star.gif";$rater_stars_txt="4.5";}
    if (
    $rater_rating >= ){$rater_stars "./img/5star.gif";$rater_stars_txt="5";}

    // 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.' stars" /> Ave. rating: '.$rater_stars_txt.'</span> from <span class="reviewcount"> '.$rater_votes.' votes</span>.';
    echo 
    '</div>';
    echo 
    '<div>';
    echo 
    '<label for="rate5_'.$rater_id.'"><input type="radio" value="5" name="rating_'.$rater_id.'[]" id="rate5_'.$rater_id.'" />Excellent</label>';
    echo 
    '<label for="rate4_'.$rater_id.'"><input type="radio" value="4" name="rating_'.$rater_id.'[]" id="rate4_'.$rater_id.'" />Very Good</label>';
    echo 
    '<label for="rate3_'.$rater_id.'"><input type="radio" value="3" name="rating_'.$rater_id.'[]" id="rate3_'.$rater_id.'" />Good</label>';
    echo 
    '<label for="rate2_'.$rater_id.'"><input type="radio" value="2" name="rating_'.$rater_id.'[]" id="rate2_'.$rater_id.'" />Fair</label>';
    echo 
    '<label for="rate1_'.$rater_id.'"><input type="radio" value="1" name="rating_'.$rater_id.'[]" id="rate1_'.$rater_id.'" />Poor</label>';
    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>';

    ?>
    This is the part you will need to edit:

    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 were allowed ".$rater_ip_vote_qty." vote(s).";
    $rater_not_selected_msg="You have not selected a rating value.";
    $rater_thankyou_msg="Thankyou for voting.";
    $rater_generic_text="this item"// generic item text
    $rater_end_of_line_char="\n"// may want to change for different operating systems 
    http://www.predictionworld.co.uk/ima...tar/00star.gif save as 00star.gif
    http://www.predictionworld.co.uk/ima...tar/05star.gif save as 05star.gif
    http://www.predictionworld.co.uk/images/5star/1star.gif save as 1star.gif
    http://www.predictionworld.co.uk/ima...tar/15star.gif save as 15star.gif
    http://www.predictionworld.co.uk/images/5star/2star.gif save as 2star.gif
    http://www.predictionworld.co.uk/ima...tar/25star.gif save as 25star.gif
    http://www.predictionworld.co.uk/images/5star/3star.gif save as 3star.gif
    http://www.predictionworld.co.uk/ima...tar/35star.gif save as 35star.gif
    http://www.predictionworld.co.uk/images/5star/4star.gif save as 4star.gif
    http://www.predictionworld.co.uk/ima...tar/45star.gif save as 45star.gif
    http://www.predictionworld.co.uk/images/5star/5star.gif save as 5star.gif

    Hope This Helped

  4. #4
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    Rating systems are a great example of a very usual use of a database. You need a filename and a rating field in the table... and you're done.
    Of course there's more work, but it's pretty simple in general concept.

    check out the above code.. or look into any simple mysql/php tutorial... shouldn't be too hard to figure out
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  5. #5
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,878
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I'd just like to point out that the above post was prior to the thread being moved, to avoid making myself look like an idiot.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends franšais | entiendo espa˝ol | t˘i Ýt hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,156
    Thanks
    262
    Thanked 690 Times in 678 Posts

    Default

    Ha. I was wondering
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. #7
    Join Date
    May 2006
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default ...Makes sense

    Quote Originally Posted by Twey
    I'd just like to point out that the above post was prior to the thread being moved, to avoid making myself look like an idiot.

    AHHHH ... makes more sense now... lol

Bookmarks

Posting Permissions

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