J'ai un petit problème a éditer une requete. Je veux interroger 2 tables en même temps.
Je vous colle un bout de code qui fonctionne mais qui n'est pas idéal:
$table="produits";
include("../config.php");
$connect=mysql_connect($host,$login,$password) or die("La base de données ne peut ètre ouverte");
$selectdb=mysql_select_db($db) or die("La base de données ne peut ètre ouverte!");
$sqlquery="select * from $table";
$queryresult=mysql_query($sqlquery);
echo "<h3 align=\"center\"><img src=\"../images/gestion_produits.jpg\" alt=\"Administrer les produits\"></h3>\n";
echo "<table width='500' border='0' align='center' class='border'>";
echo "<tr >";
echo "<td colspan=\"5\"><a href=form_ajout.php><img src=\"../images/ajout_produits.jpg\" border=\"0\" alt=\"AJOUTER UN PRODUIT\"></a>";
echo "<tr >";
echo "<td class=\"titre\">No:</td>\n";
echo "<td class=\"titre\">Titre:</td>\n";
echo "<td class=\"titre\">Catégorie:</td>\n";
echo "<td class=\"titre\">Modifier:</td>\n";
echo "<td class=\"titre\">Supprimer:</td>\n";
echo "</tr>\n";
while ($row=mysql_fetch_array($queryresult))
{
$sqlquery2="select * from produits_categories where id=\"".$row["categorie_id"]."\"";
$queryresult2=mysql_query($sqlquery2);
$row2=mysql_fetch_array($queryresult2);
echo "<tr valign='top'>\n";
echo "<td>".stripslashes($row["id"])."</td>\n";
echo "<td>".stripslashes($row["nom"])."</td>\n";
echo "<td>".$row2["nom_cat"]."</td>\n";
echo "<td><a href=\"display.php?id=".$row["id"]."\"><img src=\"../images/modifier.jpg\" border=\"0\" alt=\"Edit\"></a></td>\n";
echo "<td><a href=\"supprime_news_conf.php?id=".$row["id"]."\"><img src=\"../images/supprimer.jpg\" border=\"0\" alt=\"Supprimer\"></a></td>\n";
echo "</tr>\n";
}
echo "</table><br><br>\n";
Comme vous pouvez voir j'ai 2 requête dont une qui est exécuté à l'intérieur d'une boucle qui résulte de la première requête.J'aimerais avoir une seule requête qui va m'afficher tous mes produits et le nom de la catégorie à laquel chaques produit appartient.
Voici ma table produits:
Voici ma table de produits_categories:id
nom
description
categorie_id
ord_affiche
image
Voici maintenant la requête que je ne parvient pas à faire fonctionner afin de n'avoir qu'une seule requête:id
nom_cat
image
$sqlquery="select p.id, p.nom, p.categorie_id, pc.id, pc.nom_cat ".
"from produits as p, produits_categories as pc".
"where p.categorie_id=pc.id";
Pouvez-vous m'aider s.v.p.?Merci!