Ese código me parece ineficiente lo mejor es mostrar la tabla normalmente y luego llamar a una funcion para que te muestre los artículos de ese departamento. No hay que validar nada.
 
bueno lo hice con Dreamweaver para ahorrar tiempo =) 
Código CCS   
Código CSS:
Ver originalul.tabla {
    margin: 0px;
    padding: 0px;
}
 
ul.tabla ul {
    margin: 0px;
    padding: 0px;
}
 
ul.tabla li {
    height: 10px;
    width: 200px;
    padding-top: 5px;
    padding-right: 0px;
    padding-bottom: 15px;
    padding-left: 0px;
    border: 1px solid #C1C1C1;
    float: left;
    list-style-image: none;
    list-style-type: none;
    text-align: center;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 5px;
    margin-left: 0px;
}
 
ul.tabla li.Top {
    height: 20px;
    width: 200px;
    padding-top: 10px;
    padding-right: 0px;
    padding-bottom: 10px;
    padding-left: 0px;
    border: 1px solid #ABABAB;
    float: left;
    list-style-image: none;
    list-style-type: none;
    text-align: center;
    background-color: #F5F5F5;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 25px;
    margin-left: 0px;
}
 
ul.tabla li.Top2 {
    height: 10px;
    width: 140px;
    padding-top: 10px;
    padding-right: 0px;
    padding-bottom: 10px;
    padding-left: 0px;
    border: 1px solid #ABABAB;
    float: left;
    list-style-image: none;
    list-style-type: none;
    text-align: center;
    background-color: #F5F5F5;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 10px;
    margin-left: 0px;
}
 
ul.tabla li.Articulos {
    height: 20px;
    width: 140px;
    padding-top: 10px;
    padding-right: 0px;
    padding-bottom: 10px;
    padding-left: 0px;
    border: 1px solid #ABABAB;
    float: left;
    list-style-image: none;
    list-style-type: none;
    text-align: center;
    background-color: #FEFEFE;
    margin-top: 0px;
    margin-right: 0px;
    margin-bottom: 10px;
    margin-left: 0px;
}
 
ul.tabla a {
    font-family: Verdana, Geneva, sans-serif;
    font-size: 12px;
    font-weight: bold;
    text-transform: capitalize;
    color: #000000;
    text-decoration: none;
    text-align: center;
}
 
#contenedor {
    padding: 0px;
    height: auto;
    width: 610px;
    margin-top: 0px;
    margin-right: auto;
    margin-bottom: 0px;
    margin-left: auto;
}
 
#contenedor2 {
    padding: 10px;
    height: auto;
    width: 580px;
    float: left;
    background-color: #FBFBFB;
    border: 1px solid #C1C1C1;
}
.Espacio {
    padding: 0px;
    height: 1px;
    width: 600px;
    background-color: #A7A7A7;
    float: left;
    margin-top: 25px;
    margin-bottom: 25px;
    border-top-width: 1px;
    border-top-style: solid;
    border-top-color: #979797;
}
  
Código de la tabla   
Código PHP:
Ver originalfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
  }
 
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? 
intval($theValue) : "NULL";       break;
    case "double":
      $theValue = ($theValue != "") ? 
doubleval($theValue) : "NULL";       break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
$query_Departamentos = "SELECT * FROM departamento ORDER BY nombre ASC";
  
  
Código HTML    
Código HTML:
Ver original<?php require_once('../Connections/Prueba.php'); ?>
<?php include('articulos.php'); ?>
 
  <li class="Top"><a>departamento
</a></li>   <li class="Top"><a>estado
</a></li>   <li class="Top"><a>fecha creacion
</a></li>   <?php do { ?>
    <li><a><?php echo $row_Departamentos['nombre']; ?></a></li>     <li><a><?php echo $row_Departamentos['estado']; ?></a></li>     <li><a><?php echo $row_Departamentos['fecha_registro']; ?></a></li>     <?php echo articulos($row_Departamentos['id_departamento']); ?>
<?php } while ($row_Departamentos = mysql_fetch_assoc($Departamentos)); ?>
 
<?php
mysql_free_result($Departamentos);
?>
  
  
Código de la funcion   
Código PHP:
Ver originalfunction GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  if (PHP_VERSION < 6) {
  }
 
 
  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? 
intval($theValue) : "NULL";       break;
    case "double":
      $theValue = ($theValue != "") ? 
doubleval($theValue) : "NULL";       break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}
 
function articulos($colname_Articulos)
{
    global $database_Prueba, $Prueba;
$query_Articulos = sprintf("SELECT id_articulo, nombre, cantidad, precio, fecha_registro FROM articulo WHERE departamento = %s ORDER BY nombre ASC", GetSQLValueString
($colname_Articulos, "int")); echo '<div id="contenedor2">';
 
echo '<ul class="tabla">';
echo '<li class="Top2"><a>nombre</a></li>
      <li class="Top2"><a>cantidad</a></li>
      <li class="Top2"><a>precio</a></li>
      <li class="Top2"><a>fecha</a></li>';
  do {
      echo '<li class="Articulos">'.$row_Articulos['nombre'].'</li>';
      echo '<li class="Articulos">'.$row_Articulos['cantidad'].'</li>';
      echo '<li class="Articulos">'.$row_Articulos['precio'].'</li>';
      echo '<li class="Articulos">'.$row_Articulos['fecha_registro'].'</li>';
echo '</ul>';
echo '</div>';
}
  
  
archivo conexión   
Código PHP:
Ver original# FileName="Connection_php_mysql.htm"
# Type="MYSQL"
# HTTP="true"
$hostname_Prueba = "localhost";
$database_Prueba = "tu base de datos";
$username_Prueba = "tu usuario";
$password_Prueba = "tu clave";
  
   
como se ve