![]() |
![]() |
![]() ![]()
Post
#1
|
|
Grupa: Zarejestrowani Postów: 25 Pomógł: 0 Dołączył: 4.06.2008 Ostrzeżenie: (0%) ![]() ![]() |
witajcie
![]() Dopiero zaczynam przygodę z php ![]() <?php /* Basket class for e-commerce purpose Version : 0.5 Type:Class Category:Shopping Carts License: GNU General Public License Description: This class provides methods for add, remove, update and remove all items from a basket. The basket works with a session cookie, saving the product ID and quantity in an array for simple accesing it. There's an example in this category... called "Basket example using basket class" */ class basket { var $items; var $empty; function basket() { global $cart; if(isset($cart)) { $this->items=unserialize(stripslashes($cart)); if ( gettype($this->items) == "array" ) { $this->empty=false; } else $this->empty=true; } else $this->empty=true; } function additem($id, $name, $count, $prix) { if ($this->items[$id][1] > 0 ) { $this->items[$id][1]+=$count; } else { $this->items[$id][0]=$name; $this->items[$id][1]=$count; $this->items[$id][2]=$prix; $this->items[$id][3]=stripslashes($name); } setcookie("cart",serialize($this->items),0,"/"); $this->empty=false; } function removeitem($id) { $tmp=""; // Don't forget to initialize ! if(!$this->empty) { while(list($x,$y)=each($this->items)){ if($x!=$id) $tmp[$x]=$y; }; }; $this->items=$tmp; // Or this will have no effect ! setcookie("cart",serialize($this->items),0,"/"); if(count($this->items)==0) $this->empty=true; } function resetArray($basket) { reset($basket->items); } function countItems($basket) { if(!$basket->empty) { while ( list($x,$y,) = each($basket->items) ) { $ant++; } } return $ant; } function sumItems($basket) { if(!$basket->empty) { while ( list($x,$y,) = each($basket->items) ) { $ant = $ant + $y[1]; } } return $ant; } function printItems($b) { if(!$b->empty) { while ( list($x,$y,) = each($b->items) ) { echo "$x ".$y[0]." ".$y[1]." <a href=\"$PHP_SELF?action=R&id=$x\">Remove</a><br>"; } } } function updateitem($id,$count){ $this->items[$id][1]=$count; setcookie("cart",serialize($this->items),0,"/"); } function removeall(){ setcookie("cart",NULL,0,"/"); $this->empty=true; } } ?> </body> </html> niby wygląda normalnie ale nie wiem wogóle jak tego używać ![]() zrobiłem sobie plik kosz.php gdzie ją wgrałem dalej zrobiłem sobie plik koszyk.php gdzie zaincludowałem kosz.php i chcialem wrzucic tam produkt: session_start(); include("test.php"); $basket->additem(100, ala, 1, 22); ale wywala mi błąd - to samo jak daje $cart; Czy ktoś może mi pomóc ? przewertowałem forum i jest masa tych klas ale nie ma nigdzie prostego przykładu jak wrzucic produkt jak to skasowac czy zmodyfikowac ![]() |
|
|
![]() ![]() |
![]() |
Aktualny czas: 20.08.2025 - 07:21 |