title: Ajax rate system with php
body: <p>So, I grabbed this code from <a href="http://megarush.net/5-star-rating-system-with-php-mysql-jquery-and-ajax/" rel="nofollow">here</a>. and I changed it a little to fit my db and display the rate based on my idGames, it's working fine, but now I want to do something like <a href="http://boardgamegeek.com/boardgame/59429/dark-darker-darkest" rel="nofollow">this</a>. </p>
  
  <p>How can I display the rates when I enter in the game page and rate that particular game?
  I have an <code>index.php</code> page, on which I show all my games, and I have a <code>gameview.php</code> that is the path for each game in <code>index.php</code>, so when you click in the game in index that game is displayed in gameview. Is there a way to implement that code to rate the games in <code>gameview.php</code>? I don't know if I'm being clear enough, but take that link as an example, it's exactly what I want. And I know that <code>MYSQL</code> is deprecated, but I don't know <code>MYSQLi</code> or <code>PDO</code>. So if you can help me with this I appreciate. </p>
  
  <pre><code>&lt;?php
  include_once('settings.php');
  connect();
  
  $query  = "SELECT idGames FROM jogos";
  $result = mysql_query($query);
  $ids    = array();
  while ($row = mysql_fetch_assoc($result)) {
  $ids[] = $row['idGames'];
  }
  ?&gt;
  &lt;html&gt;
  &lt;head&gt;
  &lt;/head&gt;
   &lt;body&gt;
  &lt;?php
  for ($i = 0; $i &lt; count($ids); $i++) {
  $rating_tableName = 'jogos';
  $id               = $ids[$i];
  
  $q = "SELECT total_votes, total_value FROM $rating_tableName WHERE idGames=$id";
  $r = mysql_query($q);
  
  if (!$r)
      echo mysql_error();
  while ($row = mysql_fetch_array($r)) {
  
      $v  = $row['total_votes'];
      $tv = $row['total_value'];
      if ($v)
          $rat = $tv / $v;
      else
          $rat = 0;
  
  }
  
  $j  = $ids[$i];
  $id = $ids[$i];
  echo '&lt;div class="product"&gt;
         Rate Item ' . $j . '
          &lt;div id="rating_' . $id . '" class="ratings"&gt;';
  for ($k = 1; $k &lt; 6; $k++) {
      if ($rat + 1 &gt; $k)
          $class = "star_" . $k . "  ratings_stars ratings_vote";
      else
          $class = "star_" . $k . " ratings_stars ratings_blank";
      echo '&lt;div class="' . $class . '"&gt;&lt;/div&gt;';
  }
  echo ' &lt;div class="total_votes"&gt;&lt;p class="voted"&gt; Rating:     &lt;strong&gt;' . @number_format($rat) . '&lt;/strong&gt;/5 (' . $v . '  vote(s) cast) 
          &lt;/div&gt;
      &lt;/div&gt;&lt;/div&gt;';
  }
  ?&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>