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

EDI, CMS, Outils, Scripts et API PHP Discussion :

representer un tableau d'achat


Sujet :

EDI, CMS, Outils, Scripts et API PHP

Vue hybride

Message précédent Message précédent   Message suivant Message suivant
  1. #1
    Membre habitué
    Inscrit en
    Novembre 2009
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 13
    Par défaut representer un tableau d'achat
    salut à tous je suis encor debutant en php et je souhaiterai votre aide une fois de plus.
    En fait je souhaite reprensenter un tableau qui m'affiche l'inventaire de mes achats soit

    nom du produit,la quantité,le prix(à l'unité) biensûre.

    et à la fin me calcul la somme à payer.
    et s'il marrive de reduire la quantité d'un produit qu'elle me calcule la nouvelle somme à payer.

    quand je lance le programme celui ci m'affiche: Fatal error: Cannot use [] for reading in D:\wamp\wamp\www\netbeans\Einwohner\classe_Einwohner.php on line 14

    PHP version 5.3.5
    plateforme Netbeans version 6.9.1

    voilà mon Code:
    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
    <?php
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    class Shoppingcart {
     
        protected $items = array("Korb" => array("produktname", "quantity", "price"));
     
        public function add($produktname, $quantity, $price) {
            if (is_string($produktname) && is_int($quantity) && is_float($price)) {
                 $this->$items["Korb"][] = array("produktname"=>$produktname,"quantity"=> $quantity,"price" =>$price);
               //  = $this->items["Korb"]  ;
               // $price = $this->items["Korb"] [] ;
            } else {
                echo " Sorry Produktname oder quantity oder noch Price nicht korrekt <br/> uuml;berprulm;fen Sie
                    , ob sie alle Daten richtig eingelegt haben.";
            }
        }
     
        public function delete($produktname,$quantity)
        {
            if(is_string($produktname) && is_int($quantity))
            {
                 $vorchange;
                if($this->items["Korb"]["produktname"] == $produktname)
                {
                    if($this->items["Korb"]["quantity"] >=$quantity)
                    {
                        $vorchange = $this->items["Korb"]["quantity"];
                        $rest = $vorchange - $quantity;
     
                        echo 'rest ist :'.$rest.'<br/>';
                    }
                }
            }
        }
     
        public function subtotal()
        {
            if(is_string($produktname) && is_int($quantity) && is_float($price))
            {
                $this->items["Korb"]["quantity"] = $quantity;
                $this->items["Korb"]["price"] = $price;
     
                echo 'Die Summe ist :'.$summe = $quantity * $price .'<br/>';
     
     
            }
        }
     
     
         public function display() {
      echo '<table border = "5">' .
      '<caption>Ihre Kassen Bon</caption>' .
      '<tr> <td> Artikel </td><td> Preis </td><td> Mengen </td>';
     
      for ($i = 0; $i < sizeof($this->items['Korb']); $i++) {
      echo '<tr><td>' . $this->items['WarenKorb'][$i]['produktname'] . '</td><td>' . $this->items['Korb'][$i]['price'] .
      '</td><td>' . $this->items['WarenKorb'][$i]['quantity'] . '</td></tr>';
      }
      echo
      '<tr><td></td><td></td><td>Summe: </td><td>' . number_format($this->subtotal(), 2, ",", ".") . '</td></tr>' . '</table>';
     
     
     
     
      }
     
     
    }
     
    ?>

  2. #2
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Ca doit plutot être $this->items
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  3. #3
    Membre habitué
    Inscrit en
    Novembre 2009
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 13
    Par défaut
    et comment pourrai je y remedier? peux tu me proposer une alternative??

  4. #4
    Modérateur
    Avatar de sabotage
    Homme Profil pro
    Inscrit en
    Juillet 2005
    Messages
    29 208
    Détails du profil
    Informations personnelles :
    Sexe : Homme

    Informations forums :
    Inscription : Juillet 2005
    Messages : 29 208
    Par défaut
    Une alternative a quoi ?
    N'oubliez pas de consulter les FAQ PHP et les cours et tutoriels PHP

  5. #5
    Membre habitué
    Inscrit en
    Novembre 2009
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 13
    Par défaut
    afin à resoudre le problem. .

    j essaie actuellement d'introduire la fonction sizeof dans mes methode pour voir si je peux obtenir les differentes valeurs entrées.
    voilà le code pour obtenr mes valeurs entrée.
    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
    <?php
    /* 
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    include 'classe_Einwohner.php';
     
     
     $achat = new Shoppingcart;
     
     
     $achat->add("Apfel", 3,1.6);
    $achat->add("Apfel", 2,1.6);
    $achat->add("Apfel", 4,1.6);
    $achat->add("Birne", 5,1.4);
    $achat->add("Tomato", 10,1.5);
    $achat->add("Orangen", 10,0.5);
    $achat->add("Yaourth", 40,3.5);
     
    $achat->subtotal();
    $achat->display();
     
    $achat->delete('Yaourth', 30);
     
     $achat->display();
     
    ?>

  6. #6
    Membre habitué
    Inscrit en
    Novembre 2009
    Messages
    13
    Détails du profil
    Informations forums :
    Inscription : Novembre 2009
    Messages : 13
    Par défaut
    c est bon les gars ca y est j'ai vu mon erreur merci car même pour votre aide.

    voilà à quoi celà devait ressembler:
    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
    <?php
     
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
     
    class Shoppingcart {
     
        private $items = array();
     
        public function add($produktname, $quantity, $price) {
            if ((is_string($produktname)) && (is_int($quantity)) && (is_float($price))) {
                $this->$items["Korb"][] = array("produktname" => $produktname, "quantity" => $quantity, "price" => $price);
            } else {
                echo " Sorry Produktname oder Menge oder noch Price stimmt nicht<br/> uuml;berprulm;fen Sie
                    , ob sie alle Daten richtig eingelegt haben.";
            }
        }
     
        public function delete($produktname, $quantity) {
            if (is_string($produktname) && is_int($quantity)) {
                $vorchange;
                for ($index = 0; $index < sizeof($this->items["Korb"]); $index++) {
                    if ($this->items["Korb"][$index]["produktname"] == $produktname) {
                        if ($this->items["Korb"][$index]["quantity"] >= $quantity) {
                            $vorchange = $this->items["Korb"]["quantity"];
                            $rest = $vorchange - $quantity;
                        }
                    }
                }
            }
        }
     
        public function subtotal() {
    //        if(is_string($produktname) && is_int($quantity) && is_float($price))
    //        {
            $summe = 0;
            for ($index = 0; $index < sizeof($this->items["Korb"]); $index++) {
            //$this->items["Korb"][$index]["produktname"] = $produktname;
                $summe = $this->items["Korb"][$index]["quantity"] *
                        $this->items["Korb"][$index]["price"];
            }
    //             = $quantity * $price ;
    //            }
            return $summe;
            // }
        }
     
        public function display() {
            echo '<table border = "5">' .
            '<caption>Ihre Kassen Bon</caption>' .
            '<tr> <td> Artikel </td><td> Preis </td><td> Mengen </td>';
     
            for ($i = 0; $i < sizeof($this->items["Korb"]); $i++) {
                echo '<tr><td>' . $this->items["Korb"][$i]["produktname"] . '</td><td>'
                . $this->items["Korb"][$i]["price"] . '</td><td>' . $this->items["Korb"][$i]["quantity"] . '</td></tr>';
            }
            echo
            '<tr><td></td><td></td><td>Summe: </td><td>' . number_format($this->subtotal(), 2, ",", ".") . '</td></tr>' . '</table>';
        }
     
    }
    ?>
    et le output:
    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
    <?php
     
    include 'classe_Einwohner.php';
     
     
     $achat = new Shoppingcart;
     
     
     $achat->add("Apfel", 3,1.6);
    $achat->add("Apfel", 2,1.6);
    $achat->add("Apfel", 4,1.6);
    $achat->add("Birne", 5,1.4);
    $achat->add("Tomato", 10,1.5);
    $achat->add("Orangen", 10,0.5);
    $achat->add("Yaourth", 40,3.5);
     
    //$achat->subtotal();
    $achat->display();
    //$achat->display();
    $achat->delete('Yaourth', 30);
     
           // $achat->display();
     
    ?>
    .

    bonne journée

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. [DTD] comment representer un tableau de cellule
    Par Invité dans le forum Format d'échange (XML, JSON...)
    Réponses: 4
    Dernier message: 24/11/2008, 13h45
  2. Representer un tableau
    Par elloyeen dans le forum VB.NET
    Réponses: 1
    Dernier message: 19/04/2007, 17h51
  3. [achat] tableau noir
    Par charly dans le forum La taverne du Club : Humour et divers
    Réponses: 33
    Dernier message: 18/09/2006, 19h36
  4. représentation graphique d' un tableau en c
    Par Le Lion dans le forum C
    Réponses: 5
    Dernier message: 05/07/2006, 22h46
  5. XSLT : representation HTML en tableau double entree
    Par samouille666 dans le forum XSL/XSLT/XPATH
    Réponses: 1
    Dernier message: 02/06/2006, 20h18

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