Manipulation session

Bonjour ami CCMeur

j'ai un petit script qui qui chaque fois qu'un client ajoute un produit à son panier, une ligne apparaît, lui montrant que son article est bien ajouter.
pour l'instant le script fait ça sans limiter d'article. J'aimerais savoir si il es possible de sélectionner seulement les 5 derniers ajouts de la session.
function anim_cagette()
{
echo "<table width=\"160\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\">";
if (count($_SESSION['panier']['id_article']) == false ){
echo "<tr><td width=\"160\"><a href=\"panier.php\"><img src=\"image/commun/cagette_vide.png\" width=\"160\" height=\"130\" alt=\"cagette vide\" /></a></td></tr>";
}
else {

$compteur = count($_SESSION['panier']['id_article']);
//$result[$i] = array_reverse($compteur, true);
for ($i=0 ;$i < $compteur ; $i++)
{
$id = htmlentities($_SESSION['panier']['id_article'][$i]);
$quantite = $_SESSION['panier']['quantite'][$i];
$r=mysql_query("SELECT * FROM 02_produit WHERE id=$id ");
$f=mysql_fetch_assoc($r);
$nom = $f['nom'];
$variete = $f['variete'];
$cond = $f['condsigne'];

echo "<tr><td background=\"image/commun/fond_cagette.png\" class=\"td_padding\" align=\"center\" width=\"160\">";
echo "$nom<br/>";
if (!empty($variete)){ echo "$variete<br/>";}
echo "$quantite $cond</td></tr>";

}
echo "<tr><td background=\"image/commun/fond_cagette.png\" class=\"td_padding\" align=\"center\" width=\"160\"><a href=\"panier.php\">+ d'info</a></td></tr> ";
echo "<tr><td width=\"160\"><a href=\"panier.php\"><img src=\"image/commun/cagette_pleine.png\" width=\"160\" height=\"130\" alt=\"cagette pleine\" /></a></td></tr>";
}
echo "</table>";
}

si vous voulais voir le rendu pour mieux comprendre
www.gisa.free.fr

3 réponses

  1. Contributeur
    tu fais un tableau $_SESSION['derniers_articles'][5]

    quand t'ajoutes un article, tu fais

    $_SESSION['derniers_articles'][5] = $_SESSION['derniers_articles'][4]
    $_SESSION['derniers_articles'][4] = $_SESSION['derniers_articles'][3]
    $_SESSION['derniers_articles'][3] = $_SESSION['derniers_articles'][2]
    $_SESSION['derniers_articles'][2] = $_SESSION['derniers_articles'][1]
    $_SESSION['derniers_articles'][1] = nouvel article

    en ajouteant bien sur une initialisation du tableau, ou un controle pour les cases pas encore remplies ...
    1. Mon panier marche déjà par tableau de session, il me faut juste la combine pour sélectionner les 5 dernières
      1. Contributeur
        tu ppourrais faire un tableau, dans une variable de session aussi, ou tu renseignes les 5 derniers articles .... et a chaque fois qu'il y en a un nouveau, tu décales tout vers le bas, et tu jettes l'ancien 5° ...