Comment ne pas afficher une categories qui n'a pas de produi
Posté : 24 janv. 2008, 16:49
Bonjour,
J'ai une table categorie et une table contenue.
Je veux afficher sur une même page toutes les categories et les produits qui y sont relié.
Cependant, si une categorie n'a pas de produit je ne veux pas que la categorie s'affiche.
Pouvez-vous m'indiquer comment faire svp?
Voici mon code:
J'utilise MYSQL 5.0
Merci!
J'ai une table categorie et une table contenue.
Je veux afficher sur une même page toutes les categories et les produits qui y sont relié.
Cependant, si une categorie n'a pas de produit je ne veux pas que la categorie s'affiche.
Pouvez-vous m'indiquer comment faire svp?
Voici mon code:
J'utilise MYSQL 5.0
echo "<table width=\"80%\" colspan=\"2\" rowspan=\"2\"><tr><td><b>Section publique</b></td><td><p align=\"center\"><a href=\"intranet/prive.php\">Cliquez ici pour votre section privée</a></p></td></tr></table><br><br>\n";
echo "<table class=\"border\" align=\"center\" width=\"600\">\n";
echo "<tr>\n";
echo "<td colspan=\"2\">\n";
$sql_cat="select * from categories order by nom ASC, ord_affiche desc";
$query_cat=mysql_query($sql_cat);
while ($cat=mysql_fetch_array($query_cat)){
echo "<b>".$cat["nom"]."</b><br>\n";
$sql="select * from contenue where user_id='0' and categorie_id=".$cat["categorie_id"]." order by date_post DESC, ord_affiche DESC";
$result=mysql_query($sql);
while($row2=mysql_fetch_array($result))
{
echo "<tr>\n";
echo "<td bgcolor=\"#ffcd48\"><b>".stripslashes($row2["nom"])."</b></td><td bgcolor=\"#ffcd48\" align=\"right\"><b>".$row2["date_post"]."</b></td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan=\"2\">".stripslashes($row2["description"])."</td>\n";
echo "</tr>\n";
echo "<tr>\n";
echo "<td colspan=\"2\"><a href=\"intranet/downloads/".$row2["file"]."\">".$row2["file"]."</a></td>\n";
echo "</tr>\n";
}
echo "</td>\n";
echo "</tr>\n";
}
echo "</table>\n";
Code : Tout sélectionner
CREATE TABLE `categories` (
`categorie_id` int(255) NOT NULL auto_increment,
`nom` varchar(255) NOT NULL,
`ord_affiche` int(255) NOT NULL,
PRIMARY KEY (`categorie_id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;
CREATE TABLE `contenue` (
`id` int(255) NOT NULL auto_increment,
`nom` varchar(255) character set utf8 NOT NULL,
`description` mediumtext character set ucs2 NOT NULL,
`user_id` int(255) NOT NULL default '0',
`file` varchar(255) character set utf8 NOT NULL,
`ord_affiche` int(255) NOT NULL default '0',
`date_post` date NOT NULL,
`categorie_id` int(255) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT CHARSET=latin1 AUTO_INCREMENT=23 ;