1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
<?php // code de creation d'une session
session_start();// ouverture d'une session
$table=array();// declaration d'un variable $table vide
if(isset($_SESSION['paniercomposants']));///test sur la session ssi existe
else $_SESSION['paniercomposants']=$table;//sinon on la cree et on l'affecte un tableau vide pour commencé
?>
<?php
// require_once('../kernel/begin.php');
//require_once('../download/download_begin.php');
//require_once('../kernel/header.php');
echo $idProduit=$_GET["idp"]; echo '<br>';
echo $nomProduit=$_GET["nom"]; echo '<br>';
echo $prixProduit=$_GET["prix"]; echo '<br>';
$tableproduit=$_SESSION['paniercomposants']; // affecter le contenu de ession dans le $tableproduit
if($tableproduit=='')
{
$count=0;
echo "le panier est vide";
}
else
{ $count=count($tableproduit[0]); // tester la tail de session
echo "le panier n'est pas vide";
//echo ' count'; echo $count;
///if($count>0)
//{
//$array = array();
//for($j=0; $j<$count ; $j++){// parourrire de tableau de session
//echo $tableproduit[$j];
//$arrayindice[$j] = $j;
//}
}
?>
<?php
//$ref=$_GET["id"];
$nom=$_GET["nom"];
$prix=$_GET["prix"];
//$existe=false;
$tableproduit=$_SESSION['paniercomposants'];
if($tableproduit==0)
{
$qt=1;
//$count=0;
$tableproduit[0][0]=$nom;
$tableproduit[1][0]=$prix;
$tableproduit[2][0]=$qt;
$_SESSION['paniercomposants']=$tableproduit;
}
else
{
$count=count($tableproduit[0]);
for($j=0; $j<=$count; $j++)
{
if($tableproduit[0][$j]==$nom)
{
$tableproduit[2][$j]=$tableproduit[2][$j]+1;
echo ' existe dejas';
echo '<a href="ConsulterPanier.php">Consulter panier</a>';
$_SESSION['paniercomposants']=$tableproduit;
exit();
}
else
{
$nbr = $count +1;
$qt=1;
$tableproduit[0][$nbr]=$nom;
$tableproduit[1][$nbr]=$prix;
$tableproduit[2][$nbr]=$qt;
$_SESSION['paniercomposants']=$tableproduit;
}
}
}
?>
<a href="ConsulterPanier.php">Consulter panier</a>
<?php
//require_once('../kernel/footer.php'); ?> |
Partager