<? //接收页面变量,并放入数组 // 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"> </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%"> </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>"); ?>