全功能的php购物车

<?
//接收页面变量,并放入数组 
//
session_start(); 
if(!
session_is_registered('stationery')) session_register('stationery');
    
//清空购物栏
    
if ($action=="clear") unset($stationery);
    
//如果是更新购物栏
    
if ($action=="update" && isset($num_num))
    {
    for (
$c=0;$c<$num_num;$c++)
        {
        
$jj="num".$c;
        
$stationery[$c]['num']=$$jj;         
        }
    }
    if (
$action=="del" && isset($no))
    {
    
$stationery[$no]['id']="null"
    }
    if (
$action=="order")
    {
    echo 
"买单了";
    }
    if (isset(
$id))
    {
    
$i=count($stationery);
    if(
$i==0
       {   
          
$stationery[$i]['id']=$id
          
$stationery[$i]['name']=$name
          
$stationery[$i]['price']=$price
          
$stationery[$i]['unit']=$unit
          
$stationery[$i]['num']=1
          echo 
"空的购物栏";
       }else { 
          for(
$j=0;$j<$i;$j++) 
            { 
            if(
$stationery[$j]['id']==$id
              {
              
$stationery[$j]['num']=$stationery[$j]['num']+1;
              break;
              }else{
                if (
$j==($i-1))
                {
                 
$stationery[$i]['id']=$id;         //如没有记录,给数组增添一个元素 
                 
$stationery[$i]['name']=$name
                 
$stationery[$i]['price']=$price
                 
$stationery[$i]['unit']=$unit
                 
$stationery[$i]['num']=1;          //数量初始化为1 
                 
}

              }
            }
       }
     
reset($stationery);    
     }  
print(
"您的购物篮现在有已下货品:<br>");
       
//购物列表
       
print ("<form method="POST" action="./char.php?action=update" id="form2" name="form2"><table><tr><td align="center" width="40" bgcolor="#60ACC8">数量</td>
       
<td align="center" width="60" bgcolor="#60ACC8">型号</td>
       <
td align="center" width="60" bgcolor="#60ACC8">价钱</td>
       <
td align="center" width="60" bgcolor="#60ACC8">总价</td>
       <
td align="center" width="70">&nbsp;</td></tr>");
       $s_total=0;
       $num_num=0;
       for ($a=0;$a<count($stationery);$a++)
       
{
       $t_id=$stationery
[$a]['id'];
       $num_num+=1;
       if ($t_id!="
null")
           
{
           $t_name=$stationery
[$a]['name'];
           $t_price=$stationery
[$a]['price'];
           $t_unit=$stationery
[$a]['unit'];
           $t_num=$stationery
[$a]['num'];
           $total=$t_num*$t_price;
           $h_total+=$total;
           print ("
<tr>");
           print "
<td>$t_id<INPUT TYPE="text" NAME="num$a" value="$t_num" size="3" maxlength="3"></td>"; 
           print "
<td>$t_name</td>";
           print "
<td>¥$t_price</td>";
           print "
<td>¥$total</td>";
           print "
<td><a href=./char.php?action=del&no=$a><img SRC="./images/del.gif" WIDTH=41 HEIGHT=17 BORDER=0 ALT="$t_id"></a></td>";
           print ("
<tr>");
           }
       }
    print ("
<INPUT TYPE="hidden" name="num_num" value="$num_num" ></table>");
    print ("
<table width="290" border="0">
                  <
tr
                    <
td width="33%">总计费用</td>
                    <
td width="33%">&nbsp;</td>
                    <
td colspan="3" width="33%" align="left">¥$h_total</td>
                    <
input type="hidden" name="number" value="2">
                  </
tr>
                </
table>");
    print ("
<table>
                  <
tr
                    <
td
                      <
input type="IMAGE" value="Update Order" src="./images/refresh.gif" width="77"     height="17" border="0" alt="更新购物篮" id="IMAGE1" name="IMAGE1">
                    </
td>
                     </
form>
                      <
form method="POST" action="./char.php?action=clear" id="form2" name="form2">
                      <
td
                        <
p
                      <
input type="IMAGE" value="Clear Order" src="./images/empty.gif" width="77"     height="17" border="0" alt="清空购物篮" id="IMAGE2" name="IMAGE2">
                      </
td>
                    </
form>
                    <
form method="POST" action="./char.php?action=order" id="form3" name="form3">
                      <
td
                        <
p
                          <
input type="IMAGE" value="Purchase" src="./images/order_now.gif" width="77"     height="17" border="0" alt="下定单" id="IMAGE3" name="IMAGE3">
                      </
td>
                    </
form>
                  </
tr>
                </
table>");
?> 

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值