哪位有用session做的购物车的例子,在线等!! 很难吗?把商品id和数量存入session即可。 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 详注及 用例 http://blog.csdn.net/twt326/archive/2004/11/10/176059.aspx google php+购物车到php.net去下,好多 <?phpclass wfCart { var $total = 0; var $itemcount = 0; var $items = array(); var $itemprices = array(); var $itemqtys = array(); var $iteminfo = array(); function cart() {} // constructor function function get_contents() { // gets cart contents $items = array(); foreach($this->items as $tmp_item) { $item = FALSE; $item['id'] = $tmp_item; $item['qty'] = $this->itemqtys[$tmp_item]; $item['price'] = $this->itemprices[$tmp_item]; $item['info'] = $this->iteminfo[$tmp_item]; $item['subtotal'] = $item['qty'] * $item['price']; $items[] = $item; } return $items; } // end of get_contents function add_item($itemid,$qty=1,$price = FALSE, $info = FALSE) { // adds an item to cart if(!$price) { $price = wf_get_price($itemid,$qty); } if(!$info) { $info = wf_get_info($itemid); } if($this->itemqtys[$itemid] > 0) { // the item is already in the cart.. // so we'll just increase the quantity $this->itemqtys[$itemid] = $qty + $this->itemqtys[$itemid]; $this->_update_total(); } else { $this->items[]=$itemid; $this->itemqtys[$itemid] = $qty; $this->itemprices[$itemid] = $price; $this->iteminfo[$itemid] = $info; } $this->_update_total(); } // end of add_item function edit_item($itemid,$qty) { // changes an items quantity if($qty < 1) { $this->del_item($itemid); } else { $this->itemqtys[$itemid] = $qty; // uncomment this line if using // the wf_get_price function // $this->itemprices[$itemid] = wf_get_price($itemid,$qty); } $this->_update_total(); } // end of edit_item function del_item($itemid) { // removes an item from cart $ti = array(); $this->itemqtys[$itemid] = 0; foreach($this->items as $item) { if($item != $itemid) { $ti[] = $item; } } $this->items = $ti; $this->_update_total(); } //end of del_item function empty_cart() { // empties / resets the cart $this->total = 0; $this->itemcount = 0; $this->items = array(); $this->itemprices = array(); $this->itemqtys = array(); $this->itemdescs = array(); } // end of empty cart function _update_total() { // internal function to update the total in the cart $this->itemcount = 0; $this->total = 0; if(sizeof($this->items > 0)) { foreach($this->items as $item) { $this->total = $this->total + ($this->itemprices[$item] * $this->itemqtys[$item]); $this->itemcount++; } } } // end of update_total}?> 关于COM的疑问 懂cakephp的帮忙看一下这段cakephp的代码,为什么AuthComponent::user('id')取不到值 问个JQUERY传值问题 PHP入门书籍推荐 連接flashmediaserver服務器成功後,可不能發布FLV文件 $_FILES的问题????急哦!!! 取得文件後綴名用什麼函數 熟悉GD的朋友进来一下! 如何删除多维数组中指定元素? php初学,android怎么访问同一局域网里已经写好的php项目 如何将图片上传到数据库,或者上传图片路径到数据库。不够再加分。在线等! 请问高手:关于POST的问题
http://blog.csdn.net/twt326/archive/2004/11/10/176059.aspx
php+购物车
到php.net去下,好多
var $total = 0;
var $itemcount = 0;
var $items = array();
var $itemprices = array();
var $itemqtys = array();
var $iteminfo = array(); function cart() {} // constructor function function get_contents()
{ // gets cart contents
$items = array();
foreach($this->items as $tmp_item)
{
$item = FALSE; $item['id'] = $tmp_item;
$item['qty'] = $this->itemqtys[$tmp_item];
$item['price'] = $this->itemprices[$tmp_item];
$item['info'] = $this->iteminfo[$tmp_item];
$item['subtotal'] = $item['qty'] * $item['price'];
$items[] = $item;
}
return $items;
} // end of get_contents
function add_item($itemid,$qty=1,$price = FALSE, $info = FALSE)
{ // adds an item to cart
if(!$price)
{
$price = wf_get_price($itemid,$qty);
} if(!$info)
{
$info = wf_get_info($itemid);
} if($this->itemqtys[$itemid] > 0)
{ // the item is already in the cart..
// so we'll just increase the quantity
$this->itemqtys[$itemid] = $qty + $this->itemqtys[$itemid];
$this->_update_total();
} else {
$this->items[]=$itemid;
$this->itemqtys[$itemid] = $qty;
$this->itemprices[$itemid] = $price;
$this->iteminfo[$itemid] = $info;
}
$this->_update_total();
} // end of add_item
function edit_item($itemid,$qty)
{ // changes an items quantity if($qty < 1) {
$this->del_item($itemid);
} else {
$this->itemqtys[$itemid] = $qty;
// uncomment this line if using
// the wf_get_price function
// $this->itemprices[$itemid] = wf_get_price($itemid,$qty);
}
$this->_update_total();
} // end of edit_item
function del_item($itemid)
{ // removes an item from cart
$ti = array();
$this->itemqtys[$itemid] = 0;
foreach($this->items as $item)
{
if($item != $itemid)
{
$ti[] = $item;
}
}
$this->items = $ti;
$this->_update_total();
} //end of del_item
function empty_cart()
{ // empties / resets the cart
$this->total = 0;
$this->itemcount = 0;
$this->items = array();
$this->itemprices = array();
$this->itemqtys = array();
$this->itemdescs = array();
} // end of empty cart
function _update_total()
{ // internal function to update the total in the cart
$this->itemcount = 0;
$this->total = 0;
if(sizeof($this->items > 0))
{
foreach($this->items as $item) {
$this->total = $this->total + ($this->itemprices[$item] * $this->itemqtys[$item]);
$this->itemcount++;
}
}
} // end of update_total}
?>