http://www.phpe.net/class/46.shtml
http://www.phpe.net/class/44.shtml
http://www.phpe.net/class/40.shtml
http://www.phpe.net/class/39.shtml
www.phpe.net是个好地方

解决方案 »

  1.   

    <?php
    $data = array(
      s001 => array(名称=>"甲",单价=>100.00),
      s002 => array(名称=>"乙",单价=>110.00),
      s003 => array(名称=>"丙",单价=>90.00),
      s004 => array(名称=>"丁",单价=>10.00),
      s005 => array(名称=>"戊",单价=>30.00),
      s006 => array(名称=>"己",单价=>50.00),
    );
    ?>
    mail.htm
    <frameset cols="*,*">
     <frame src=list.php name=list>
     <frame src=mycart.php name=mycart>
    </frameset>list.php
    商品列表
    <form method=post target=mycart action=mycart.php>
    <table>
    <tr><th>名称</th><th>单价</th><th>数量</th></tr>
    <?php
    include "data.php";
    foreach($data as $k=>$v)
      echo "<tr><td>$v[名称]</td><td>$v[单价]</td><td><input type=text name='id[$k]' size=3 value=$数量></td></tr>";
    ?>
    </table>
    <input type=submit name=cart value="加入购物车">
    </form>mycart.php // 显示和修改购物车
    <?
    session_start();
    include "data.php";if(isset($_POST['id']))
     foreach($_POST['id'] as $k=>$v) {
       if($v > 0) {
         $_SESSION['cart'][$k] = $data[$k];
         $_SESSION['cart'][$k][数量] = $v;
       }else if($_POST['cart'] == "刷新")
         unset($_SESSION['cart'][$k]);
     }
    if(!is_array($_SESSION['cart']))
      exit;
    ?>
    <form method=post>
    <table>
    <tr><th>名称</th><th>单价</th><th>数量</th></tr>
    <?php
    foreach($_SESSION['cart'] as $k=>$v)
      echo "<tr><td>$v[名称]</td><td>$v[单价]</td><td><input type=text name='id[$k]' size=3 value=$v[数量]></td></tr>";
    ?>
    </table>
    <input type=submit name=cart value="刷新">
    </form>