<?php header("Content-type:text/html;charset=utf8"); //调用实例 require_once 'Cart.class.php'; session_start(); if(!isset($_SESSION['cart'])) { $_SESSION['cart'] = new Cart; } $cart =& $_SESSION['cart']; if( ($_SERVER['REQUEST_METHOD']=="POST")&&($_POST['action']=='add') ){ $p = $_POST['p']; $items = $cart->add($p); } if( ($_GET['action']=='remove')&&($_GET['key']!="") ) { $items = $cart->remove($_GET['key']); } if( ($_SERVER['REQUEST_METHOD']=="POST")&&($_POST['action']=='modi') ){ $key = $_POST['key']; $value = $_POST['value']; for($i=0;$i<count ($key);$i="" $items="$cart-" ){="">modi($key[$i],$value[$i]); } } $items = $cart->getCart(); //打印 echo ""; setlocale(LC_MONETARY, 'it_IT'); foreach($items as $item){ echo ""; echo "<table><tbody><tr><form action="\"index.php\"" method="\" post\??=""></form><td>ID:".$item['ID']."<input type="hidden" value=".$item['ID'].">"; echo "</td><td>产品:".$item['name']; echo "</td><td>单价:".$item['price']; echo "</td><td><input value=".$item['count'].">"; $sum = $item['count']*$item['price']; echo "</td><td>合计:".round($sum,2); echo "</td><td><input type="button" value="删除">"; } echo "<input type="hidden" value="modi">"; echo "</td></tr><tr><td colspan="7"><input type="submit" value="提交查询内容">"; echo "</td></tr></tbody></table>"; ?> <hr> <form action="tmp.php" method="post"> ID:<input> 品名:<input> 单价:<input> 数量:<input> <input type="hidden" value="add"> <input type="submit" value="提交查询内容"> </form></count>
更多关于PHP相关内容感兴趣的读者可查看本站专题:《PHP+MySQL购物车开发专题》、《php面向对象程序设计入门教程》、《PHP数学运算技巧总结》、《PHP数组(Array)操作技巧大全》、《php字符串(string)用法总结》、《PHP数据结构与算法教程》、《php程序设计算法总结》、《php正则表达式用法总结》、及《php常见数据库操作技巧汇总》