<h2>大苹果购物网</h2>
<?php session_start(); include("DADB.class.php"); $db=new DADB(); ?> <table border="1" width="100%" cellpadding="0" cellspacing="0"> <tr> <td>代号</td> <td>水果名称</td> <td>水果价格</td> <td>原产地</td> <td>货架</td> <td>库存量</td> <td></td> </tr> <?php $uid=$_SESSION["uid"]; $sql="select * from fruit"; $arr=$db->Query($sql); foreach($arr as $v) { echo"<tr> <td>{$v[0]}</td> // 从数据库调出我们所需要的内容 <td>{$v[1]}</td> <td>{$v[2]}</td> <td>{$v[3]}</td> <td>{$v[4]}</td> <td>{$v[5]}</td> <td><a href='add.php?ids={$v[0]}'>添加</a></td> //这里的购物相当于添加购物车的功能 </tr>"; } ?> <?php //这里显示的是 购物车有多少产品,和产品的总价格 $ann=array(); if(!empty($_SESSION["gwc"])) { $ann=$_SESSION["gwc"]; } $zhonglei = count($ann); $sum=0; foreach($ann as $k) { $sql1="select price from fruit where ids='{$v[0]}'"; $danjia=$db->Query($sql1); foreach($danjia as $n) { $sum=$sum + $n[0]*$k[1]; } } echo"购物车有<mark>{$zhonglei}</mark>种商品,总价格为<mark>{$sum}</mark>元"; ?> </table> <div> <a href="gouwuche.php" rel="external nofollow" rel="external nofollow" >查看购物车</a> <a href="main.php" rel="external nofollow" rel="external nofollow" >浏览商品</a> <a href="zhanghu.php" rel="external nofollow" rel="external nofollow" >查看账户</a> </div> </body>