Ec (2); & lt ;? If (! $ Session & amp ;! $ Scid) {$ sessionmd5 (uniqid (rand (); SetCookie (scid, $ session, time () 14400);} * lastnumberisexpirationtimeinseconds, 14400sec4hrs * script ec (2); script
If (! $ Session &&! $ Scid ){
$ Session = md5 (uniqid (rand ()));
SetCookie ("scid", "$ session", time () 14400 );
}/* Last number is expiration time in seconds, 14400 sec = 4 hrs */
Class Cart {
Function check_item ($ table, $ session, $ product ){
$ Query = "SELECT * FROM $ table WHERE session = '$ session' AND product =' $ product '";
$ Result = mysql_query ($ query );
If (! $ Result ){
Return 0;
}
$ NumRows = mysql_num_rows ($ result );
If ($ numRows = 0 ){
Return 0;
} Else {
$ Row = mysql_fetch_object ($ result );
Return $ row-> quantity;
}
}
Function add_item ($ table, $ session, $ product, $ quantity ){
$ Qty = $ this-> check_item ($ table, $ session, $ product );
If ($ qty = 0 ){
$ Query = "insert into $ table (session, product, quantity) VALUES ";
$ Query. = "('$ session', '$ product',' $ quantity ')";
Mysql_query ($ query );
} Else {
$ Quantity = $ qty;
$ Query = "UPDATE $ table SET quantity = '$ quantity' WHERE session = '$ session' AND ";
$ Query. = "product = '$ product '";
Mysql_query ($ query );
}
}
Function delete_item ($ table, $ session, $ product ){
$ Query = "delete from $ table WHERE session = '$ session' AND product =' $ product '";
Mysql_query ($ query );
}
Function modify_quantity ($ table, $ session, $ product, $ quantity ){
$ Query = "UPDATE $ table SET quantity = '$ quantity' WHERE session = '$ session '";
$ Query. = "AND product = '$ product '";
Mysql_query ($ query );
}
Function clear_cart ($ table, $ session ){
$ Query = "delete from $ table WHERE session = '$ session '";
Mysql_query ($ query );
}
Function cart_total ($ table, $ session ){
$ Query = "SELECT * FROM $ table WHERE session = '$ session '";
$ Result = mysql_query ($ query );
If (mysql_num_rows ($ result)> 0 ){
While ($ row = mysql_fetch_object ($ result )){
$ Query = "SELECT price FROM inventory WHERE product = '$ row-> product '";