query1($in_list); $num_rows = mysql_num_rows($db->rs1); $datum = date("Y-m-d"); // they don't have that product in their cart? Put it in. if($num_rows == 0) { $sql = "INSERT INTO $table (session,OGLID,quantity,datum) VALUES "; $sql .= "('$session','$OGLID','$quantity','$datum')"; $db->query1($sql); } // They have the product in their cart already? Add the quantity they specified // to the product they have in their cart else { $row = mysql_fetch_array($db->rs1); $quantity = $quantity + $row[quantity]; $sql = "UPDATE $table SET quantity='$quantity' WHERE "; $sql .= "session='$session' AND OGLID='$OGLID'"; $db->query1($sql); } } // delete a specified item function delete_item($table,$session,$OGLID) { global $db; $db->query1("DELETE FROM $table WHERE session='$session' AND OGLID='$OGLID'"); } // modifies a quantity of an item function modify_quantity($table, $session, $OGLID, $quantity) { $sql = "UPDATE $table SET quantity='$quantity' "; $sql .= "WHERE session='$session' AND OGLID='$OGLID'"; mysql_query("$sql"); } // clear all content in their cart function clear_cart($table,$session) { mysql_query("DELETE FROM $table WHERE session='$session'"); } //add up the shopping cart total function cart_total($table,$session) { $result = mysql_query("SELECT * FROM $table WHERE session='$session'"); if(mysql_num_rows($result) >0) { while($row = mysql_fetch_array($result)) { // look up the item in inventory // $price_from_inventory = "SELECT price FROM inventory WHERE "; // $price_from_inventory .= "OGLID = '$row[product]'"; // $result_inventory = mysql_query("$price_from_inventory"); // $row_price = mysql_fetch_array($result_inventory); //calculate the total $total = 1; // $total + ($row_price[price]*$row[quantity]); } } return $total; } function display_contents($table,$session) { $count = 0; $result = mysql_query("SELECT * FROM $table WHERE session='$session'"); while($row = mysql_fetch_array($result)) { $result_inv = mysql_query("SELECT oglasi.id as ID, oglas FROM oglasi WHERE ID='$row[OGLID]'"); $row_inventory = mysql_fetch_array($result_inv); $contents["OGLID"][$count] = $row_inventory[ID]; $contents["oglas"][$count] = $row_inventory[oglas]; $contents["price"][$count] = 1 ; // $row_inventory[price]; $contents["quantity"][$count] = $row[quantity]; $contents["total"][$count] = 1 ; // ($row_inventory[price] * $row[quantity]); $count ++; } $total = $this->cart_total($table,$session); $contents["final"] = $total; return $contents; } function get_ids($table,$session) { global $db; $aIds = ""; $count = 0; $sIdOgl = ""; $db->query1("SELECT * FROM $table WHERE session='$session'"); while($rs=mysql_fetch_object($db->rs1)) { $aIds[$count] = $rs->oglid; $count ++; } if ($count > 0) { $sIdOgl = implode(",", $aIds); } return $sIdOgl; } function num_items($table, $session) { global $db; $db->query1("SELECT * FROM $table WHERE session='$session'"); $num_rows = mysql_num_rows($db->rs1); //$result = mysql_query("SELECT * FROM $table WHERE session='$session'"); //$num_rows = mysql_num_rows($result); return $num_rows; } } ?>