This is a piece of code that displays name and picture of employees. I'm using '$employee_counter' to count the right number of cells for each row, in this case 4. When the counter reaches 4, it is reset. Also, the employees are divided up by which office they work at, so for each new instance of $office, a kind of heading row with the name of the office is created. I hope you can use some of this to solve your problem.
/nina
$employee_query="SELECT * FROM user ORDER BY office ASC, surname ASC, firstname ASC";
$employee_query2="SELECT * FROM user ORDER BY office ASC";
$employee_result=mysql_query($employee_query);
$employee_result2=mysql_query($employee_query2);
$office=mysql_result($employee_result2, 0, 'office');
//Initialise counter for employees per tablerow
$employee_counter=1;
echo "<BR>";
echo "<CENTER>";
echo "<TABLE CLASS='table' BORDER='0' CELLPADDING='6' CELLSPACING='0'>";
echo "<TR CLASS='tablebackground'>";
echo "<TD COLSPAN='4'>";
echo "<P CLASS='tabletext'>";
echo $office;
echo "</P>";
echo "</TD>";
echo "</TR>";
echo "<TR>";
while ($employee_array=mysql_fetch_array($employee_result))
{
if ($office!=$employee_array['office'])
{
$office=$employee_array['office'];
echo "<TR CLASS='tablebackground'>";
echo "<TD COLSPAN='4'>";
echo "<P CLASS='tabletext'>";
echo $office;
echo "</P>";
echo "</TD>";
echo "</TR>";
$employee_counter=1;
}
echo "<TD>";
if ($employee_array['picture'])
{
echo "<CENTER>";
echo "<IMG SRC='getpicture.php?username=$employee_array[username]';>";
echo "</CENTER>";
}
echo "<P CLASS='preamblec'>";
echo $employee_array['firstname'];
echo " ";
echo $employee_array['surname'];
echo " nr: ".$employee_counter;
echo "</P>";
echo "</TD>";
if ($employee_counter==4)
{
echo "</TR>";
echo "<TR>";
//Reset counter
$employee_counter=0;
}
$employee_counter++;
}
echo "</TABLE>";
echo "</CENTER>";