title: Update column with +1 increment based on columns with duplicate value
body: <p>I have a mysql table with 3 columns (<code>itemid</code>, <code>altid</code>, <code>counter</code>)</p>
  
  <p>I am having a difficult time looping through each row to update the <code>counter</code> column based on the number of duplicate <code>itemid</code>'s.</p>
  
  <p>Example of what I am trying to accomplish:</p>
  
  <pre><code>itemid | altid | counter
  1        30      1
  1        31      2
  1        37      3
  5        53      1
  5        54      2
  6        112     1
  6        113     2
  6        114     3
  6        115     4
  </code></pre>
  
  <p>Notice where the <code>itemid</code> is duplicated, the <code>counter</code> is incrementing +1.</p>
  
  <p>The list goes on about 2500 rows. My <code>counter</code> column is empty. I have had no luck with the increment inside a while loop to update in php because I don't know how to detect that duplicate value (or checking that previous value).</p>
  
  <p>This is all I have right now (doesn't work):</p>
  
  <pre><code>$query = mysql_query("SELECT * FROM table") or die(mysql_error());
  while ($row = mysql_fetch_assoc($query)){
  $itemid = $row['itemid'];
  $i=1;
      if($row['itemid']!=$itemid){
      $i=1;
      }
  $id = $row['id'];
  $query = mysql_query("UPDATE table SET counter='$i' WHERE id=$id") or die(mysql_error());
  $i++;
  }
  </code></pre>
  
  <p>I searched and haven't found much to help accomplish this. Any help, or push in the right direction would be very much appreciated! </p>