Add a counter before the loop and if in the loop.
$i = 1;
while($row = mysql_fetch_array($query)) {
$image = $row[2];
echo "<td>";
echo '<img src="data:image/png;base64,' . base64_encode($image) . '" />';
echo "</td>";
if($i++%10 == 0) echo '</tr><tr>';
}