PHP MySQL 购物车程序实例
分类:威尼斯登录首页

? 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' ";

本文由威尼斯在线注册平台发布于威尼斯登录首页,转载请注明出处:PHP MySQL 购物车程序实例

上一篇:在反串行化多少个目的后 下一篇:php判定客商浏览器类型与来自页面
猜你喜欢
热门排行
精彩图文