Hmpf, irgendwie raffis net. Ich habe folgende Codes:
class.php:
	
class_test.php:
	
Das ist ja ne abgewandelste version von der Beispiel Klasse von php.net.
Wenn ich jetzt add_item das erste mal benutze, gehts ganz gut.
Beim 2. Mal wirds aber nimmer dazugezählt. Also der Wert beträgt imer noch 1. Was mach ich falsch???
					class.php:
PHP-Code:
	
	
<?php
class cart{
var $items;
var $total;
    function add_item($article, $plus=1){
        $this->items[$article]+=$plus;
        $this->total+=$plus;
        return TRUE;
    }
    
    function del_item($article, $minus=1){
        if($items[$article]>=$minus){
            $this->items[$article]-=$minus;
            $this->total-=$minus;
            return TRUE;
        }else{
            return FALSE;
        }
    }
    
    function del_all(){
        unset($this->items);
        if(empty($this->items)) return TRUE;
        else return FALSE;
    }
    
    function get_item($item){
        return $this->items[$item];
    }
    
    function get_total(){
        return $this->total;
    }
    
    function get_items(){
        $return="";
        if($this->items!=""){
            foreach($this->items as $itms=>$num){
                $return.="Nr. $itms: $num<br />";
            }
            $return.="Total: ".$this->total;
            return $return;
        }else{
            return FALSE;
        }
    }
}
?>
PHP-Code:
	
	
<?php
include_once("class.php");
$cart=new cart;
$_SESSION['on']=1;
$action=$_GET['action'];
$item=$_GET['item'];
if(!empty($action)) $cart->$action($item,1);
?>
<a href='class_test.php?action=add_item&item=1'>Item hinzufügen</a>
<a href='class_test.php?action=del_item&item=1'>Item löschen</a>
<a href='class_test.php?action=del_all'>Warenkorb leeren</a>
<?php
echo "<br />Items:<br />".$cart->get_items();
?>
Wenn ich jetzt add_item das erste mal benutze, gehts ganz gut.
Beim 2. Mal wirds aber nimmer dazugezählt. Also der Wert beträgt imer noch 1. Was mach ich falsch???
 
          




 )
 ) 
 
Kommentar