Actual implementation of 5-star rating system

624 views Asked by At

I want to implement a 5-star rating system into my web page. I'm totally new to using php, but I've got the system set up and working. I am able to create as many rating boxes as I want and have them working, but my question is..

How do I place the rating stars near my images? In this case, I want 10 different images to be rated. The code I use on my "page.php":

Array:

<?php
include("settings.php");
connect();
$ids=array(1,2,3,4,5,6,7,8,9,10);
?>

<html>

Body:

 <?php
    for($i=0;$i<count($ids);$i++)
        {
            $rating_tableName     = 'ratings';
         $id=$ids[$i];
     $q="SELECT total_votes, total_value FROM $rating_tableName WHERE id=$id";
    $r=mysql_query($q);
    if(!$r) echo mysql_error();
    while($row=mysql_fetch_array($r))
    {
        $v=$row['total_votes'];
        $tv=$row['total_value'];
        $rat=$tv/$v;

        }



        $j=$i+1;
        $id=$ids[$i];
    echo'<div class="product">
               Rate Item '.$j.'
                <div id="rating_'.$id.'" class="ratings">';
                    for($k=1;$k<6;$k++){
                        if($rat+0.5>$k)$class="star_".$k."  ratings_stars ratings_vote";
                        else $class="star_".$k." ratings_stars ratings_blank";
                        echo '<div class="'.$class.'"></div>';
                        }
                    echo' <div class="total_votes"><p class="voted"> Rating: <strong>'.@number_format($rat).'</strong>/5 ('.$v. '  vote(s) cast) 
                </div>
            </div></div>';}
    ?> 
0

There are 0 answers