This might do the trick (untested):
$z = 0;
while ($row = mysql_fetch_array($q)) {
$pic = $row['url'];
if ($z == 0)
$content .= "<tr>\n\t<td><a href='".$pic."' target='_blank'><img src='".$pic."' border='0' /></a></td>\n";
elseif ($z % 4 == 0)
$content .= "</tr>\n<tr>\n";
else
$content .= "\t<td><a href='".$pic."' target='_blank'><img src='".$pic."' border='0' /></a></td>\n";
$z++;
}
or if you want to start from 1 then remove the $z = 0; and the $z++ from the body of the loop and change youe while (...) to look like:
while (++$z && $row = mysql_fetch_array($q))