<?php
/**
 * 根据Cookie值对购物车商品数量和总价格调用
 */
 require("class/connect.php");
  
 $totalProducts = 0;    //购物车商品总数
 $totalPrice = 0.0;        //购物车商品总价
  
 //  |77,243|2!|77,237|3!
 $cookieString = explode("!",$_COOKIE['zeuqcmybuycar']);
  
 try{
      //遍历商品
     for($i = 0; $i < count($cookieString)-1; $i++){
         $priceAndNumber = explode("|",$cookieString[$i]);
         $thisNum = $priceAndNumber[2];            //当前商品的数量
         $thisId = explode(",",$priceAndNumber[1]);
         $thisId = $thisId[1];                    //当前商品的ID
         $thisPrice = this_price($thisId);        //当前商品价格
          
         $totalPrice += $thisPrice * $thisNum;    //购物车商品总价累加
         $totalProducts += $thisNum;                //购物车商品总数累加
     }
      
     echo "document.write(/"".displayResultJs($totalPrice,$totalProducts)."/")";    //显示结果Js形式输出
      
 }catch (Exception $e){
     echo $e->getMessage();
 }
      
     return $row['price'];
 }
  
 /**链接数据库*/
 function connectDB(){
     global $phome_db_server,$phome_db_username,$phome_db_password,$phome_db_dbname,$phome_db_char;
     $connect = new mysqli($phome_db_server,$phome_db_username,$phome_db_password,$phome_db_dbname);
     $connect -> query("set Names ".$phome_db_char);
     return $connect;//开源软件:Cuoxin.com
 }
  
 /**显示结果Js*/
 function displayResultJs($totalPrice,$totalProducts){
     return "<div class='car'>您的购物车中有 {$totalProducts} 件商品,总计金额 ¥{$totalPrice}元。<br />点击查看   <a href='/e/ShopSys/buycar/'>结算>></a> </div>";
 }
?>
 

dawei

【声明】:毕节站长网内容转载自互联网,其相关言论仅代表作者个人观点绝非权威,不代表本站立场。如您发现内容存在版权问题,请提交相关链接至邮箱:bqsm@foxmail.com,我们将及时予以处理。