Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?
- session_start();
- class cart {
- private $items;
- function __construct() { // init
- $this->items = array();
- }
- function add($id,$amount,$price,$pages){
- $this->items[$id]['amount'] += $amount;
- $this->items[$id]['price'] = $price;
- $this->items[$id]['pages'] = $pages;
- }
- function remove($id){
- unset($this->items[$id]);
- }
- function update($id,$what,$val){
- $this->items[$id][$what] = $val;
- }
- function save(){
- $_SESSION['cart'] = $this;
- }
- function items(){
- return $this->items;
- }
- public static saveToDB($cart) {
- $query = sprintf("INSERT INTO Carts (timeCreated, cartObject) VALUES(UNIX_TIMESTAMP(), '%s')", mysql_real_escape_string(serialize($cart)));
- mysql_query($query);
- return mysql_insert_id();
- }
- public static loadFromDB($id) {
- $query = sprintf("SELECT cartObject FROM Carts WHERE ID = %d", $id);
- $data = mysql_fetch_assoc(mysql_query($query));
- return unserialize($data['cartObject']);
- }
- }
- ?>
Add Comment
Please, Sign In to add comment