Affichage par catégorie

stu76 Messages postés 186 Date d'inscription samedi 5 mars 2005 Statut Membre Dernière intervention 17 février 2008 - 1 févr. 2006 à 11:57
stu76 Messages postés 186 Date d'inscription samedi 5 mars 2005 Statut Membre Dernière intervention 17 février 2008 - 1 févr. 2006 à 16:33
Bonjour à tous,

je suis en train de dévellopper une application dans laquelle, je dois pouvoir afficher des produits par catégorie. Pour l'instant j'arrive à afficher l'ensemble des enregistrements toutes catégories confondue. Mon objetcif est de pouvoir afficher uniquement les enregistrement d'une catégorie par exemple : carte mère. Pour cela j'aimerais utiliser un menu déroulant, mais je sais pas comment faire le lien entre le menu déroulant et l'affichage par catégorie. Si quelqu'un pouvait m'aider se serait sympa, je ne demande pas la solution mes des explications ou un exemple pour que je puisse comprendre.
Pour que vous puissiez comprendre voici mon source :

<?php require_once('Connections/ecommerce.php'); ?>
<title>Articles</title>
<style type="text/css">
<!--
.Style1 {font-family: Arial, Helvetica, sans-serif}
body,td,th {
color: #FFFFFF;
font-family: Arial, Helvetica, sans-serif;
}
body {
background-color: #333333;
background-image: url(images/fondsite.gif);
}
a:link {
color: #FFFFFF;
text-decoration: none;
}
a:visited {
color: #FFFFFF;
text-decoration: none;
}
a:hover {
color: #FF0000;
text-decoration: none;
}
a:active {
text-decoration: none;
}
.Style4 {font-size: small}
.Style5 {
color: #FF0000;
font-size: small;
}
-->
</style>
Retour,
Attention !!! Atconcept se r&eacute;serve le droit de modifier ses prix sans pr&eacute;avis.,

----

Afficher :,
<form name="Afficher" method="post" action="">

<select name="choix">
<option value="carte mère" <?php if (!(strcmp("carte mère", $row_Fabricant['id']))) {echo "SELECTED";} ?> >Carte m&egrave;re</option>
<option value="HDD" selected <?php if (!(strcmp("HDD", $row_Fabricant['id']))) {echo "SELECTED";} ?>>HDD</option>
<option value="carte graphique" <?php if (!(strcmp("carte graphique", $row_Fabricant['id']))) {echo "SELECTED";} ?>>Carte graphique</option>
<option value="Tower" <?php if (!(strcmp("Tower", $row_Fabricant['id']))) {echo "SELECTED";} ?>>Tower</option>
<option value="Mémoire" <?php if (!(strcmp("Mémoire", $row_Fabricant['id']))) {echo "SELECTED";} ?>>M&eacute;moire</option>
<?php
do {
?>
<option value="<?php echo $row_Fabricant['id']?>"<?php if (!(strcmp($row_Fabricant['id'], $row_Fabricant['id']))) {echo "SELECTED";} ?>><?php echo $row_Fabricant['id']?></option>
<?php
} while ($row_Fabricant = mysql_fetch_assoc($Fabricant));
$rows = mysql_num_rows($Fabricant);
if($rows > 0) {
mysql_data_seek($Fabricant, 0);
$row_Fabricant = mysql_fetch_assoc($Fabricant);
}
?>
</select>

</form>

<table width="761" border="0" cellpadding="0">
<tr>
<td width="97">N&deg;</td>
<td width="69">Catégorie</td>
<td>Nom d'article </td>
<td width="124">Prix HTVA en &euro; </td>
<td width="114">Prix TVAC en &euro; </td>
</tr>
<tr>
<?php
mysql_select_db($database_ecommerce, $ecommerce);
$sql1='SELECT shop_articles.id, shop_articles.nom_article, shop_articles.prix_ht, shop_articles.prix_ttc, shop_articles.rubarticle1, shop_catégories.intitule
FROM shop_articles Inner join shop_catégories on shop_catégories.id=shop_articles.rubarticle1 where shop_articles.rubarticle1=shop_catégories.id';
$req=mysql_query($sql1) or die('Erreur SQL!
'.$sql1.'
'.mysql_error());
while ($row_articles=mysql_fetch_array($req))
{
?>
<tr>
<td height="19"><?php echo $row_articles[id]; ?></td>
<td height="19"><?php echo $row_articles[intitule]; ?></td>
<td width="259"><?php echo $row_articles[nom_article]; ?></td>
<td>
<?php echo $row_articles[prix_ht]; ?>
</td>
<td>
<?php echo $row_articles[prix_ttc]; ?>
</td>
</tr>
<?php '
'.$row_articles[id].' '.$row_articles[nom].' '.$row_articles[nom_article].' '.$row_articles[prix_ht].' '.$row_articles[prix_ttc].'';
}
mysql_close();
?>

Merci d'avance pour ceux qui se pencherons sur mon prob.

@+ et bonne prog,

Stu76

4 réponses

cs_Anthomicro Messages postés 9433 Date d'inscription mardi 9 octobre 2001 Statut Membre Dernière intervention 13 avril 2007 8
1 févr. 2006 à 12:16
Salut,

mettons que tu ais un select (que tu rempliras avec une requête de type SELECT contenant tes catégories)

<select name="categorie">
<option value="1">Cartes-mères</option>
<option value="2">Cartes-graphiques</option>
</select>

ensuite sur ta page php traitant le tout :

if(isset($_POST['categorie']) AND is_numeric($_POST['categorie']))
{
mysql_connect('hote','user','passe');
mysql_select_db('base');
$requete=mysql_query('SELECT machin FROM table WHERE categorie='.$_POST['categorie']);
mysql_close();
etc...
while($r=mysql_fetch_row($requete))
{
etc...
}
}

<hr size="2" width="100%"><li>Entraide, dépannage et vulgarisation informatique : Mon site de vulgarisation informatique</li><li>Codes-php.net</li>
0
stu76 Messages postés 186 Date d'inscription samedi 5 mars 2005 Statut Membre Dernière intervention 17 février 2008 1
1 févr. 2006 à 13:31
Salut Anthomicro,

Merci pour ton coup de main, j'ai bien lu ton code et j'ai essayé de l'appliquer à mon code mais j'ai un message d'erreur qui s'affiche se message est le suivant :
Parse error: syntax error, unexpected T_LOGICAL_AND, expecting ',' or ')' in c:\wamp\www\ecommerce\articles.php
Si je comprend bien il me dit qu'il y a une erreur avec le and, apparement je ne peux pas écrire ce code de cette manière j'ai chercher à comprendre pourquoi et je ne comprend pas. Ce serait vraiment sympa si tu pouvais jetter un coup d'oeil et me guider car la je nage.
Revoici le code, j'ai mis la ligne qui pose problème en gras avec une astérix devant :

<tr bgcolor="#000000">
<td width="75">Afficher : </td>
<td width="593" align="center" valign="middle"><form name="Afficher" method="post" action="">
<select name="catégorie">
<option value="1">Software</option>
<option value="2">Ecran</option>
<option value="3">Mémoire</option>
<option value="4">Portable</option>
<option value="5">Processeur</option>
</select>
</form></td>
</tr>
</table>
<table width="761" border="0" cellpadding="0">
<tr>
<td width="97">N&deg;</td>
<td width="69">Catégorie</td>
<td>Nom d'article </td>
<td width="124">Prix HTVA en &euro; </td>
<td width="114">Prix TVAC en &euro; </td>
</tr>
<tr>
<?php
* if(isset($_POST['catégorie'] and is_numeric($_POST['catégorie']))
{
mysql_select_db($database_ecommerce, $ecommerce);
$sql1='SELECT shop_articles.id, shop_articles.nom_article, shop_articles.prix_ht, shop_articles.prix_ttc, shop_articles.rubarticle1, shop_catégories.intitule
FROM shop_articles Inner join shop_catégories on shop_catégories.id=shop_articles.rubarticle1 where shop_articles.rubarticle1='.$_POST['catégorie']';
$req=mysql_query($sql1) or die('Erreur SQL!
'.$sql1.'
'.mysql_error());
while ($row_articles=mysql_fetch_array($req))
{
?>
<tr>
<td height="19"><?php echo $row_articles[id]; ?></td>
<td height="19"><?php echo $row_articles[intitule]; ?></td>
<td width="259"><?php echo $row_articles[nom_article]; ?></td>
<td>
<?php echo $row_articles[prix_ht]; ?>
</td>
<td>
<?php echo $row_articles[prix_ttc]; ?>
</td>
</tr>
<?php '
'.$row_articles[id].' '.$row_articles[nom].' '.$row_articles[nom_article].' '.$row_articles[prix_ht].' '.$row_articles[prix_ttc].'';
}
mysql_close();
?>

Encore merci pour ton aide, car j'aimerais vraiment comprendre le principe, je connais pas bien le PHP, je viens de m'y mettre. D'habitude je travail avec delphi, mais c'est pas du tout génial pour le dévelloppement d'application ecommerce.


@+

Stu76
0
cs_Anthomicro Messages postés 9433 Date d'inscription mardi 9 octobre 2001 Statut Membre Dernière intervention 13 avril 2007 8
1 févr. 2006 à 13:37
t'as oublié une parenthèse :

if(isset($_POST['catégorie'] and is_numeric($_POST['catégorie']))

> if(isset($_POST['catégorie']) and is_numeric($_POST['catégorie'])) <hr size "2" width="100%"><li>Entraide, dépannage et vulgarisation informatique : Mon site de vulgarisation informatique</li><li>Codes-php.net</li>
0
stu76 Messages postés 186 Date d'inscription samedi 5 mars 2005 Statut Membre Dernière intervention 17 février 2008 1
1 févr. 2006 à 16:33
Re salut Anthomicro,

Merci pour ton coup de pouce, j'ai appliquer les modifications et je comprend parfaitement le code. Par contre, quand je l'exécute dans mon navigateur, rien ne s'affiche. Ce qui n'est pas logique, car dans ma requête SQL je vérifie bien si la valeur de ma table articles est égale à la valeur de ma table catégorie grace à la valeur que me renvoi la méthode post. Pourtant rien ne s'affiche, je ne sais pas si l'erreur si situe au niveau du php / sql ou si c'est un problème dans mon code html notament la partie ci-dessous en vert.
Pourrais-tu juste encore jetter un coup d'oeil et me donner ton avis, se serait super sympa.

<tr bgcolor="#000000">
<td width="75">Afficher : </td>
<td width="593" align="center" valign="middle"><form name="Afficher" method="post" action="articles.php">


<select name="categorie">
<option value="1">Software</option>
<option value="2">Ecran</option>
<option value="3">Mémoire</option>
<option value="4">Portable</option>
<option value="5">Processeur</option>
</select>

</form></td>
</tr>
</table>
<table width="761" border="0" cellpadding="0">
<tr>
<td width="97">N&deg;</td>
<td width="69">Catégorie</td>
<td>Nom d'article </td>
<td width="124">Prix HTVA en &euro; </td>
<td width="114">Prix TVAC en &euro; </td>
</tr>
<tr>
<?php
if(isset($_POST['categorie'])and is_numeric($_POST['categorie']))
{
mysql_select_db($database_ecommerce, $ecommerce);
$sql1='SELECT shop_articles.id, shop_articles.nom_article, shop_articles.prix_ht, shop_articles.prix_ttc, shop_articles.rubarticle1, shop_catégories.intitule FROM shop_articles Inner join shop_catégories on shop_catégories.id=shop_articles.rubarticle1 where shop_articles.rubarticle1='.$_POST['categorie'];
$req=mysql_query($sql1) or die('Erreur SQL!
'.$sql1.'
'.mysql_error());
mysql_close();
while ($row_articles=mysql_fetch_array($sql1))
{
?>
<tr>
<td height="19"><?php echo $row_articles[id]; ?></td>
<td height="19"><?php echo $row_articles[intitule]; ?></td>
<td width="259"><?php echo $row_articles[nom_article]; ?></td>
<td>
<?php echo $row_articles[prix_ht]; ?>
</td>
<td>
<?php echo $row_articles[prix_ttc]; ?>
</td>
</tr>
<?php '
'.$row_articles[id].' '.$row_articles[nom].' '.$row_articles[nom_article].' '.$row_articles[prix_ht].' '.$row_articles[prix_ttc].'';
}
}
?>

Encore mille merci et à bientôt,

@+

Stu76
0
Rejoignez-nous