just replace the array with the result set.
<table border="0" width="100%">
$arr = array('test1','test2','test3','test4','test5','test6');
$x=0;
while(list($name,$val)= each($arr))
{
if($x==0)
{
print '<tr>';
}
print '<td>'.$val.'</td>';
$x++;
if($x==4)
{
print '</tr>';
$x=0;
}
}
if($x<>0)
{
$rest = 4-$x;
for($i=0;$i<$rest;$i++)
{
print '<td> </td>';
}
print '</tr>';
}
</table>