Try something like this
$queryset=mysql_query("select * from pictures where setname='$setname'");
echo "<table id='setthumbs'><tr>";
$i = 0;
while($rowset = mysql_fetch_array($queryset)){
if ( ($i % 4) == 0 && 0 != $i ) {
echo "</tr><tr>";
}
echo "<td><a href='#' onclick=\"picchange('$rowset[id]')\"><img src='images/s-$rowset[id].jpg' ></a></td>";
$i++;
}
echo "</tr></table>";
if ( ($i%4) == 0 && 0 != $i ) {
This line is where all the action happens really. We first test to see if we need to close the previous row and create another. What it does is uses the modulus operator %. In short this does a divide but only gets the remainder. we check for 0 (meaning whole number). However since $i = 0 on the first iteration we do not want to execute the code in the if so we add the 0 != $i
The 4 in this basically means we want 4 columns.