I've got a table of products that customers are permitted to election on. Within this table, there's a votes column, store the quantity of votes that item has gathered, along with a rank column, that's a ranking of products in line with the quantity of votes they've (i.e. most votes will get rank 1, second most will get rank 2, etc.)

Presently, I am recalculating the rank of each and every item after every election. That's, whenever a user votes, I add someone to that item's votes column, after which update every rank using the following query:

SET @rank = 0
UPDATE items SET rank = @rank := @rank + 1 ORDER BY votes DESC

This works typically, but does not consume to account voting ties. Basically have votes [10, 4, 3, ], I'd expect ranks [1, 2, 3, 4]. However, basically have votes [10, 10, 3, 0], I'd like ranks [1, 1, 3, 4]. This does not happen I get ranks [1, 2, 3, 4].

How do i incorporate ties like I have referred to above?

I would not save the rank in database. You are able to calculate it while showing the end result.

$rank = 1;
$lastVotes = -1;
$lastAdd = 0;

$query = mysql_query("SELECT * FROM table WHERE * ORDER BY votes DESC", $link);
while( $row = mysql_fetch_array( $query ) ) {
  // local variable with votes
  $votes = $row['votes'];

  // check if we have a tie
  if( $lastVotes == $votes ) {
    // don't change rank if there is a tie but inc $lastAdd
    $lastAdd += 1;
  } else {
    // there is no tie: save last votes, adjust $rank and reset $lastAdd
    $lastVotes = $votes;
    $rank += $lastAdd;
    $lastAdd = 1;

  // $rank is your rank

This inelegant solution would return that which you desire:

update ITEMS I1
   set rank =
         (select count(*)
            from ITEMS I2
           where I2.VOTES >= I1.VOTES)
         - (select count(*) - 1
              from ITEMS I3
             where I3.VOTES = I1.VOTES)

No mysql instance to do this on, but what about something similar to this:

    SELECT v.id, v.votes, r.rank
      FROM votes v
          ,(SELECT votes, @rownum = @rownum + 1 AS rank
              FROM votes
              GROUP BY votes
              ORDER BY votes DESC
           ) r
      WHERE v.votes = r.votes
      ORDER BY rank

Determine the distinct group of "votes", organize them, give each several, then use that to connect the amount (rank) to each election.

Really is dependent up for grabs size, as well as on the freq of updates, but what about a trigger? MySQL- Trigger updating ranking