probleme panier

Petit nouveau ! | 8 Messages

25 juin 2006, 15:57

Bonjour,
je suis en train de mettre en place un panier ou caddie sur un site et...le panier se remplie bien comme il faut à chaque fois que je rajoute un article, mais si je réctualise lapage ou si je reviens à la page précédente sans rien choisir puis retourne dans mon panier, le dernier article du panier se rajoute tout seul(si je réactualise 10 fois, j'ai 10 fois le même article en plus dans le panier)
Pouvez-vous m'aider.
voici le code pour la page panier:
<?php 

//session: 
$_SESSION['idpiecefin'][]=$idpiecefin; 
$_SESSION['designation'][]=$designation; 
$_SESSION['prix'][]=$prix; 

?> 

<h3>votre panier</h3> 
<table border="1"> 
<tr> 
<th>idpiecefin</th> 
<th>designation</th> 
<th>prix</th> 
<?php 

//affichage panier: 
for($i=0; $i<count($_SESSION['idpiecefin']); $i++){ 
$requete="SELECT idpiecefin, designation, prix 
FROM finpieces 
WHERE idpiecefin='".$_SESSION['idpiecefin'][$i]."'"; 
$result=mysql_query($requete, $idlink); 
while($tab=mysql_fetch_assoc($result)) 
{ 
echo 
"<tr> 
<td>", $tab['idpiecefin'], "</td> 
<td>", $tab['designation'], "</td> 
<td>", $tab['prix'], "</td> 
</tr>"; 
} 
} 
echo "</table>"; 

?> 

Eléphant du PHP | 82 Messages

25 juin 2006, 16:07

Salut,


Il faut que la page d'affichage du panier, et la page d'ajout de tes articles soient différentes.

++

Mammouth du PHP | 19672 Messages

25 juin 2006, 18:01

Solution dans ce tuto
Codez en pensant que celui qui maintiendra votre code est un psychopathe qui connait votre adresse :axe:

Invité
Invité n'ayant pas de compte PHPfrance

25 juin 2006, 20:33

Solution dans ce tuto


Merci Cyrano pour ce magnifique tuto qui je pense m'apportera la solution
Réponse dans quelques jours

Invité
Invité n'ayant pas de compte PHPfrance

26 juin 2006, 17:27

Salut,


Il faut que la page d'affichage du panier, et la page d'ajout de tes articles soient différentes.

++
c'est le cas , merci
un lien "ajouter au panier" existe bien dans les pages catalogues

Invité
Invité n'ayant pas de compte PHPfrance

27 juin 2006, 15:32

Solution dans ce tuto


Merci Cyrano pour ce magnifique tuto qui je pense m'apportera la solution
Réponse dans quelques jours
Euh, en fait , ce n'est pas si simple
moi j'ai des variables récuperées de l'URL
Et là, c'est le contraire, je n'arrive à placer qu' un article à la fois dans le panier :

mes variables récupérer de l'URL:
$ifp
$DESIGNATION[$i]
$PRIX[$j]


le code panier:
<?php

$_SESSION['panier']=array();
$_SESSION['panier']['idpiecefin']=array();
$_SESSION['panier']['designation']=array();
$_SESSION['panier']['prix']=array();
$_SESSION['panier']['qte']=array(); 

//$_SESSION['panier']['designation']=$designation;

$select=array();
$select['id']=$ifp;
$select['designation']=$DESIGNATION;
$select['prix']=$PRIX;
$select['qte']=1;
ajout($select);

if(!isset($_SESSION['panier'])){
	$_SESSION['panier']=array();
	$_SESSION['panier']['idpiecefin']=array();
	$_SESSION['panier']['designation']=array();
	$_SESSION['panier']['prix']=array();
	$_SESSION['panier']['qte']=array();
	}
	
function ajout($select)
{	
array_push($_SESSION['panier']['idpiecefin'], $select['id']);
array_push($_SESSION['panier']['designation'], $select['designation']);
array_push($_SESSION['panier']['prix'], $select['prix']);
array_push($_SESSION['panier']['qte'], $select['qte']);
}

?>
	

<h3>votre panier</h3>
<table border="1">
	<tr>
		<th>idpiecefin</th>
		<th>designation</th>
		<th>prix</th>
		<th>quantite</th>
		<th>suppression</th>
	</tr>
<?php
//affichage panier:	
	for($i=0; $i<count($_SESSION['panier']['idpiecefin']); $i++){

	$requete="SELECT idpiecefin, designation, prix
			FROM finpieces
			WHERE idpiecefin='".$_SESSION['panier']['idpiecefin'][$i]."'";
	$result=mysql_query($requete, $idlink);
	while($tab=mysql_fetch_assoc($result))
	{
	echo
	"<tr>
	<td>", $tab['idpiecefin'], "</td>
	<td>", $tab['designation'], "</td>
	<td>", $tab['prix'], "</td>
	<td>", $tab['qte'], "</td>
	<td> supprimer article </td>
	</tr>";
	}
	}
echo "</table>";
?>/*php  /php*/