$query = mysql_query('SELECT `id`, `name`, `icon` FROM `portfolio` ORDER BY `id`');
$num = mysql_num_rows($query);
$i = 0;
$count = 0;
while($i < $num)
{
$id = mysql_result($query,$i,'id');
$name = mysql_result($query,$i,'name');
$icon = mysql_result($query,$i,'icon');
$code = '
<td>
<table border="0" cellpadding="0" cellspacing="0" width="100%">
<tr>
<td background="templates/Lost_Love/images/content/box/port_top_bg.jpg" width="120" height="9"></td>
</tr>
<tr>
<td align="center" background="templates/Lost_Love/images/content/box/port_middle_bg.jpg" width="120">
<table border="0" cellpadding="0" cellspacing="0" width="100">
<tr>
<td background="templates/Lost_Love/images/content/box/port_screen_bg.jpg" style="border:0px;" width="100" height="100"><a href="javascript:unhide(\'port_viewer' . $id . '\');" title="' . $name . '"><img src="port/' . $icon . '"></a></td>
</tr>
</table>
</td>
</tr>
<tr>
<td background="templates/Lost_Love/images/content/box/port_bottom_bg.jpg" width="120" height="9"></td>
</tr>
</table>
</td>';
if($count == 0)
{
if($i = $num - 1)
{
echo '
<tr>' . $code . '
</tr>';
}
else
{
echo '
<tr>' . $code;
$count = 1;
}
}
else if($count == 1)
{
if($i = $num - 1)
{
echo '
<td width="15"></td>' . $code . '
</tr>';
$count = 0;
}
else
{
echo '
<td width="15"></td>' . $code . '
<td width="15"></td>';
$count = 2;
}
}
else
{
echo $code . '
</tr>';
$count = 0;
}
$i++;
}