title: How to reflect changing rankings instantly?
body: <p>Basically what's going on is I've been trying to develop a ratings system that stores users total ratings and also displays the items in order based on their ratings.  But now I ran into a bug that only changes the ratings/display after rating twice as opposed to obviously just once. </p>
  
  <p>Here's the code: </p>
  
  <pre><code>&lt;?php
  include ("sql.php");
  
  function getTotal($name) {
  $query = "SELECT total FROM items WHERE name = '$name'";
  // echo $query;
  // echo "&lt;br /&gt;";
  $result = mysql_query($query);
  $row = mysql_fetch_row($result);
  return $row[0];
  }
  
  
  
  display();
  function display($items) {
      $video = getTotal(video);
      // echo "video total: ".$video;
      // echo "&lt;br /&gt;";
      $Music = getTotal(Music);
      // echo "Music total: ".$Music;
      // echo "&lt;br /&gt;";
      $football = getTotal(football);
      // echo "football total: ".$football;
      // echo "&lt;br /&gt;";
  
      $items = array($video =&gt; 'video', $Music =&gt; 'Music', $football=&gt;'football');
      // echo "&lt;br /&gt;";
      krsort($items);
      // print_r($items);
  foreach ($items as $key =&gt; $val) {
      print ("&lt;form method = 'post'&gt;
      $val
      &lt;button name ='upvote' type = 'submit' value ='$val' /&gt;Upvote&lt;/button&gt;
      &lt;button name ='downvote' type ='submit' value ='$val' /&gt;Downvote&lt;/button&gt;
      &lt;/form&gt; TOTAL: ".$key."
          ");
      }
  }
  
  if (isset($_POST['upvote']) || isset($_POST['downvote'])) {
  
  $ip = 23;
  //$ip = ip2long($_SERVER['REMOTE_footballDR']);
  
  if ($_POST['upvote'] != null) {
  $item = $_REQUEST['upvote'];
  }
  else {
  $item = $_REQUEST['downvote'];
  }
  
  //see if person has voted before, for this item
  $q = "SELECT count(*) FROM tracker".$item." WHERE ip = $ip";
  $check = mysql_query($q);
  $row = mysql_fetch_row($check);
  $bool = ($row[0] &gt; 0);
  
      if (!$bool) {
          echo "User has not voted before for this item &lt;br /&gt;";
  
      }
  
      else {
          echo "user has voted for this item before";
          //then the user has voted before
          //row[0] = ip, row[1] = value
          $d = "SELECT * FROM tracker".$item." WHERE ip = '$ip'";
          $e = mysql_query($d);
          $row = mysql_fetch_row($e);
          $value = -$row[1];
          echo "&lt;br /&gt; value: ".$value;
          $qry = "UPDATE items SET total = total + $value WHERE name = '$item'";
          echo "&lt;br /&gt; qry: ".$qry;
          $result = mysql_query($qry);
  
          if (!$result) {
              echo "problem with result".mysql_error();
  
          }
  
  
          $q = "DELETE FROM tracker".$item." WHERE ip = '$ip'";
          echo "&lt;br /&gt; Delete query".$q; 
          $r = mysql_query($q);
          if (!$r) {
              echo "problem with r".mysql_error();
          }
  
      }
  
  
  
  if ($item == $_POST['upvote']) {
      echo "&lt;br /&gt; item has been upvoted";
      $qry = "UPDATE items SET total = total + 1 WHERE name = '$item'";
      echo "&lt;br /&gt; qry: ".$qry;
      mysql_query($qry);
  
  //also get the ip footballdress and footballd to the who's voted table
      $d = "INSERT INTO tracker".$item." VALUES ('$ip', '1')";
      mysql_query($d);
      }
  
  elseif ($item == $_POST['downvote']) {
      echo "&lt;br /&gt; item has been downvoted";
      $qry = "UPDATE items SET total = total - 1 WHERE name = '$item'";
      mysql_query($qry);
  
  //also get the ip footballdress and footballd to the who's voted table
      $d = "INSERT INTO tracker".$item." VALUES ('$ip', '-1')";
      mysql_query($d);
      }
  }
  </code></pre>