Précédent   Forum des professionnels en informatique > PHP > Scripts
Scripts Forum d'entraide sur les scripts PHP téléchargés. Les meilleurs scripts PHP, la FAQ scripts PHP, toutes les FAQ PHP
Partagez cette discussion sur d'autres réseaux sociaux : Viadeo Twitter Google Facebook Digg Delicious MySpace Yahoo
Réponse Proposer ce sujet en actualité
 
Outils de la discussion
Publicité
'
Vieux 03/06/2011, 13h17   #1
 
Steffleo Yooh
Inscription : novembre 2009
Messages : 13
Détails du profil
Informations personnelles :
Nom : Steffleo Yooh

Informations forums :
Inscription : novembre 2009
Messages : 13
Points : -2
Points : -2
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 :
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>';
 
 
 
 
  }
 
 
}
 
?>
steff.leo est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/06/2011, 13h19   #2
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Ca doit plutot être $this->items
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/06/2011, 13h21   #3
 
Steffleo Yooh
Inscription : novembre 2009
Messages : 13
Détails du profil
Informations personnelles :
Nom : Steffleo Yooh

Informations forums :
Inscription : novembre 2009
Messages : 13
Points : -2
Points : -2
et comment pourrai je y remedier? peux tu me proposer une alternative??
steff.leo est déconnecté   Envoyer un message privé Réponse avec citation 02
Vieux 03/06/2011, 13h53   #4
Modérateur
 
Avatar de sabotage
 
Homme Vincent
Inscription : juillet 2005
Messages : 14 929
Détails du profil
Informations personnelles :
Nom : Homme Vincent

Informations forums :
Inscription : juillet 2005
Messages : 14 929
Points : 16 381
Points : 16 381
Une alternative a quoi ?
sabotage est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/06/2011, 14h05   #5
 
Steffleo Yooh
Inscription : novembre 2009
Messages : 13
Détails du profil
Informations personnelles :
Nom : Steffleo Yooh

Informations forums :
Inscription : novembre 2009
Messages : 13
Points : -2
Points : -2
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 :
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();
 
?>
steff.leo est déconnecté   Envoyer un message privé Réponse avec citation 00
Vieux 03/06/2011, 14h48   #6
 
Steffleo Yooh
Inscription : novembre 2009
Messages : 13
Détails du profil
Informations personnelles :
Nom : Steffleo Yooh

Informations forums :
Inscription : novembre 2009
Messages : 13
Points : -2
Points : -2
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 :
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 :
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
steff.leo est déconnecté   Envoyer un message privé Réponse avec citation 00
Réponse Proposer ce sujet en actualité Cette discussion est résolue.
Outils de la discussion



Fuseau horaire GMT +2. Il est actuellement 18h30.


 
 
 
 
Partenaires

Hébergement Web