<?

// ------------------------------------------------------------------------- //
// Affiche dans un tableau sur 2 colonnes toutes les catégories d'une table  //
// items, avec tri par catégorie, nombre d'items / catégories et nb total.   //
// ------------------------------------------------------------------------- //
// Auteur: J-Pierre Dézélus                                                  //
// Email:  jpdezelus@phpinfo.net                                             //
// Web:    http://www.phpinfo.net/                                           //
// ------------------------------------------------------------------------- //

@mysql_connect($hote, $user, $pass);

$sql  = "SELECT categorie, count(categorie) ";
$sql .= "FROM items ";
$sql .= "GROUP BY categorie ";
$sql .= "ORDER BY categorie";

$resultat = mysql_db_query($cfgBase, $sql);
$cpt = 0;
$total = 0;

while (
$enr = mysql_fetch_array($resultat))
{
    
$tCat[$cpt] = Array($enr[0], $enr[1]);
    
$total += $enr[1];
    
$cpt++;
}

echo
"<CENTER><TABLE BORDER='0' CELLPADDING='0' CELLSPACING='1'>\n";
echo
"<TR><TD ALIGN='center' COLSPAN='2'>Catégories<TD></TR>\n";

$moitie = ceil(sizeof($tCat) / 2) - 1;
for (
$cpt = 0; $cpt <= $moitie; $cpt++)
{
    echo
"<TR><TD ALIGN='center' WIDTH='50%'>&nbsp;";
    echo
"<A HREF=\"./?p=items&cat=".urlencode($tCat[$cpt][0])."\">";
    echo
$tCat[$cpt][0]."</A>";
    echo
" (".$tCat[$cpt][1].")&nbsp;";
    echo
"</TD><TD ALIGN='center' WIDTH='50%'>&nbsp;";

    if (
$tCat[$cpt+$moitie+1][0] != "") {
      echo
"<A HREF=\"./?p=items&cat=".urlencode($tCat[$cpt+$moitie+1][0])."\">";
      echo
$tCat[$cpt+$moitie+1][0]."</A>";
      echo
" (".$tCat[$cpt+$moitie+1][1].")&nbsp;";
    }
    echo
"</TD></TR>\n";
}

echo
"</TABLE>\n";
echo
"[ <B>".($total)."</B> items ]</CENTER>\n";

?>