On my "popular tags" page, I am fetching all of the tags from the database with this PHP & SQL in order from most popular to least popular:
$sql = "SELECT t.tagid, t.name, t.desc, COUNT(qt.id) AS total
FROM tags t
LEFT JOIN question_tags qt ON t.tagid=qt.tag_id
GROUP BY t.tagid, t.name
ORDER BY total DESC";
$result = mysql_query($sql) or die(mysql_error());
while($row=mysql_fetch_assoc($result)) {
echo '<div class="tag-list-box" id="tag-'.$row['tagid'].'">
<a href="/tags/'.strtolower($row['name']).'" class="tag">
<span class="label label-inverse label-tag">'.strtolower($row['name']).'</span>
</a> <strong>× '.$row['total'].'</strong><br />
<p>'.($row['desc']!==null ? $row['desc'] : '<em>This tag has no description.</em>').'</p>
</div>';
}
I don't have it in an HTML table right now because I thought I could do it the more "modern way" with divs and CSS, but as you can see in this screenshot below, the rows get messed up when a tag has a description because the height of the box is greater than the others:

My CSS for the boxes is:
.tag-list-box {
width: 20%;
padding: 5px;
background-color: #f0f0f0;
border: 1px solid #ccc;
float: left;
margin-right: 2%;
margin-bottom: 10px;
}
I am thinking I should put it in a table which should fix the problem but my question is how do I make every 4 rows from the query have their own <tr> so there can be 4 in each table row?
I can't figure it out — I tried doing a count and incrementing it in the while loop but then I just don't know where to go from there.