One way to do it would be to create an array of your DB results that matches the table layout you want, e.g.
$table = array();
$column = 0;
$row = 0;
$sql = mysql_query("SELECT * FROM merch");
if(!$sql) die("SQL ERROR: ".mysql_error());
while($result = mysql_fetch_array($sql)){
$table[$row][$column] = $result;
$column++;
if ($column>2) {
$column = 0;
$row++;
}
}
You can then use foreach() to loop through your array and put the <TR> tags in the right places.