looks to me like you are re-setting $i=0 everytime you go through the while loop, maybe the below code will help a little.
echo "<table width=100% bgcolor=#FFFFFF border=0 cellpadding=2 cellspacing=2>";
$query = "SELECT * FROM rpg_images WHERE gameid='12' ORDER BY gameid ASC limit $offset,$limit ";
$result = mysql_query($query) or die("Could not execute query.");
$i=1;
echo "<tr>";
while ($row = mysql_fetch_array($result))
{
if ($i%4==0)
{
echo "</tr>
echo"<tr>";
}
echo "<TD>";
$url = "show_images.php?imageid=".($row["imageid"]);
$title = "<IMG SRC=\"images/".$row[img_thumb]."\" ALT=\"Click for larger image\" WIDTH=160 HEIGHT=120 BORDER=1>";
do_html_url($url, $title);
echo"</TD>";
$i++;
// echo "<tr><td><IMG SRC=\"images/".$row[img_thumb]."\" BORDER=0></td></tr>";
}
echo "</tr>";
mysql_free_result($result);
echo "</table>";