You'd have to have a "counter" inside your while loop. WHen that counter's value is 5, create a new row.
Something like:
$i = 1;
while($row = mysql_fetch_array($result))
{
if($i % 5 == 0) // If $i / 5 has no remainder (meaning it's 5, 10, 15, 20, etc.)
{
echo '</tr>
<tr>';
}
}
How that would fit into your code is that you'd have to make each looped item it's own <td> element (instead of just a set of tables). So for example:
<?php
$sql="SELECT * from items WHERE id>50 ORDER BY rand() LIMIT 5";
$result=mysql_query($sql);
?>
<table width="95%" border="0" cellpadding="3" cellspacing="3" style="padding-top:5px">
<tr>
<?php
$i=1;
while($rows=mysql_fetch_array($result)){
if($i % 5 == 0)
{
?>
</tr>
<tr>
<?php
}
?>
<td align="center" valign="top">
<table border="0" align="center" >
<tr>
<td align="center"><a href="item.php?id=<? echo $rows['id']; ?>" target="_self"><img src="<? echo $rows['image']; ?>" alt="<?
echo "#";
echo $rows['code'];
echo " - ";
echo $rows['name'];
?>" border="0" class="mediumimage"/></a></td>
</tr>
<tr>
<td align="center" valign="middle"><a href="item.php?id=<? echo $rows['id']; ?>" class="style22">#<? echo $rows['code']; ?> - <? echo $rows['name']; ?></a></td>
</tr>
<tr>
<td align="center" valign="middle"><a href="item.php?id=<? echo $rows['id']; ?>" class="style22">£<? echo $rows['price']; ?></a></td>
</tr>
</table>
<td>
<?php
}
?>
</tr>
</table>
Hope that helps you out.