IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

Langage PHP Discussion :

Récupération de variable + tableau associatif


Sujet :

Langage PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Mars 2011
    Messages : 4
    Par défaut Récupération de variable + tableau associatif
    Bonjour,

    Je rencontre une difficulté par rapport à un panier, dans mon panier doit figurer la taille du vêtement choisi par l'internaute cela fonctionne mais quand je prends un autre article d'une taille différente le panier m'affiche pour tous les articles la même taille.

    Que dois-je faire ?

  2. #2
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    nous montrer le code problématique...

  3. #3
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Mars 2011
    Messages : 4
    Par défaut
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    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
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    <?
    session_start();
     
    if (isset($_SESSION["caddie"])) 
    {
    $caddie = $_SESSION["caddie"];
    } 
    else 
    {
    $caddie = array();
    }
     
    if (isset($sup))
    {
    unset($caddie["$sup"]);
    }
     
    if (isset($lettre))
    {
    $sizel = $lettre;
    }
     
    if (empty($_POST['pnum']))
    {
    $quantite=1;
    }
    else
    {
    $quantite=$_POST['pnum'];
    }
     
    $caddie[$article]=$caddie[$article]+$quantite;
     
    $i=0;
    if (isset($nombre[$i]))
    { 
    $a=count($_SESSION["caddie"]);
    $a--;
    for ($j=0;$j<$a;$j++)
    {
    if ((ereg("^([0-9]+)$",$nombre[$j])) && $nombre[$j]!="0")
    {
    $caddie["$produit[$j]"]=$nombre[$j];
    }
    }
    }
     
    include("design/headeri.php");
    require("config.php");
     
    $_SESSION["caddie"] = $caddie;
     
    echo"<td bgcolor=\"$barre1\"><a href=\"index.php\"><font size=\"2px\"<strong>Accueil</a> > <a href=\"liste.php?cat=1\">Homme</a> > Panier </strong></font><br><br><br></td>
      </tr>
      <tr><br>";
     
    echo"<br><center><table width=\"95%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bordercolor=\"$bordercolor\">
      <tr>
        <td><div align=\"center\"><table width=\"70%\" border=\"0\" cellspacing=\"0\" cellpadding=\"0\" bgcolor=\"$barre1\">
      <tr>
        <td width=\"30%\"><div align=\"center\"><strong><font color=\"$police3\" size=\"$width_police2\">Designation</font></strong></div></td>
        <td width=\"10%\"><div align=\"center\"><strong><font color=\"$police3\" size=\"$width_police2\">Taille</font></strong></div></td>
        <td width=\"10%\"><div align=\"center\"><strong><font color=\"$police3\" size=\"$width_police2\">Prix unitaire</font></strong></div></td>
        <td width=\"5%\"><div align=\"center\"><strong><font color=\"$police3\" size=\"$width_police2\">Quantité</font></strong></div></td>
        <td width=\"10%\"><div align=\"center\"><strong><font color=\"$police3\" size=\"$width_police2\">Prix total</font></strong></div></td>
        <td width=\"5%\"><div align=\"center\"><strong><font color=\"$police3\" size=\"$width_police2\">Supprimer</font></strong></div></td>
      </tr>";
     
     
    while($var = each($caddie))
    {
    $sql = "SELECT id_pro,titre_prod,pxht_prod,promo_prod,pxhtpromo_prod  FROM $table_produit where id_pro='$var[0]'";
    $sql = mysql_db_query($base,$sql);
     
    while ($site=mysql_fetch_array($sql))
    {
    if (empty($nombre[$i]) || !(ereg("^([0-9]+)$",$nombre[$j])) || $nombre[$j]=="0")
    {
    $nombre[$i]="$var[1]";
    }
    else
    {
    $var[1]=$nombre[$i]; 
    }
     
    if ($site[promo_prod]=="1")
    {
    $site[pxht_prod]=$site[pxhtpromo_prod];
    }
     
    $pxtotal=$site[pxht_prod]*$var[1];
    $total=$total+($site[pxht_prod]*$var[1]);
     
    echo"<tr bgcolor=\"$barre3\">
        <td><div align=\"center\">$site[titre_prod]</div></td>
        <td><div align=\"center\">$silzel</div></td>
        <td><div align=\"center\">$site[pxht_prod] €</div></td>
        <td><div align=\"center\"><form action=\"panier.php\"  method=\"post\" style='margin-top: 0px; margin-bottom: 0px'><input name=\"produit[$i]\" type=\"hidden\" value=\"$var[0]\"><input name=\"nombre[$i]\" type=\"text\" value=\"$nombre[$i]\" size=\"2\"></div><br></td>
        <td><div align=\"center\">$pxtotal €</div></td>
        <td><div align=\"center\"><a href=\"panier.php?sup=$site[id_pro]\"><img src=\"design/suprimmer.gif\" border=\"0\"onclick=\"javascript:if(!confirm('Etes-vous sûr de vouloir supprimer cet article de votre panier?')) return false;\" ></a></div></td>
      </tr>";
     
    $i++;
    $test="1";
    }
    }
     
    if ($test=="1")
    {
    echo"<tr bgcolor=\"$barre3\">
        <td>&nbsp;</td>
        <td>&nbsp;</td>
        <td><div align=\"center\"><input type=\"image\" src=\"design/recalculer.gif\" border=0></td>
        <td><div align=\"center\"><strong>Total</strong></div></td>
        <td><div align=\"center\"><strong>$total €</strong></div></td>
        <td></form></td>
      </tr>";
    }
     
    echo"</div></table></td>
      </tr>
    </table></center><br><br>";
     
    if ($test=="1")
    {
    echo"<center><table border=\"0\" cellpadding=10>
      <tr>
        <td><a href=\"index.php\"><img src=\"design/poursuis.gif\" border=\"0\"></a></td>
        <td><form action=\"compte.php\" method=\"post\" style='margin-top: 0px; margin-bottom: 0px'>
    		<input name=\"achat\" type=\"hidden\" value=\"autorisation\">
    		<input  type=\"image\" src=\"design/commande.gif\">
    		</form></td>
      </tr>
    </table></center><br><br>";
    }
    else
    {
    session_unregister("achat");
    echo"<center><strong>votre panier est vide</strong><br><br><a href=\"liste.php?cat=1\"><img src=\"design/retour.gif\" border=\"0\"></a><br><br></center>";
    }
     
     
    include("design/footer.php");
    ?>

  4. #4
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    tu as une erreur ici je crois :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    <td><div align=\"center\">$silzel</div></td>
    c'est pas $sizel ?
    Tu fais chevaucher des balises, tu fermes plusieurs balises avant de fermer ton formulaire...

  5. #5
    Futur Membre du Club
    Homme Profil pro
    Développeur Web
    Inscrit en
    Mars 2011
    Messages
    4
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France

    Informations professionnelles :
    Activité : Développeur Web
    Secteur : High Tech - Produits et services télécom et Internet

    Informations forums :
    Inscription : Mars 2011
    Messages : 4
    Par défaut
    Merci Vorace, effectivement une erreur d'étourdi comme d'habitude maintenant si je veux associer la taille choisi par le client avec l'article choisi qu'est je dois faire précisément ?
    Avec le code actuel la taille s'affiche dans mon panier mais quand je prend un autre article avec une taille différente, le panier affiche tous les articles du panier avec la dernière taille choisie ?
    Je pense que je dois créer un tableau associatif mais je sais pas comment le représenter.

  6. #6
    Membre émérite Avatar de vorace
    Homme Profil pro
    Développeur
    Inscrit en
    Août 2010
    Messages
    573
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Meurthe et Moselle (Lorraine)

    Informations professionnelles :
    Activité : Développeur

    Informations forums :
    Inscription : Août 2010
    Messages : 573
    Par défaut
    personnellement je me suis servi de ce tuto pour la création de mon panier :
    http://jcrozier.developpez.com/articles/web/panier/

Discussions similaires

  1. récupération de variables d'un tableau dans 1 autre tableau
    Par deneb92 dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 17/12/2010, 13h19
  2. [ODBC] Mettre une variable dans un tableau associatif
    Par razily dans le forum PHP & Base de données
    Réponses: 3
    Dernier message: 16/06/2010, 11h53
  3. Réponses: 9
    Dernier message: 06/06/2010, 14h22
  4. Récupération tableau associatif
    Par sohnic dans le forum Général JavaScript
    Réponses: 4
    Dernier message: 15/01/2009, 14h54
  5. Réponses: 2
    Dernier message: 15/02/2008, 21h45

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo