欧美大屁股bbbbxxxx,狼人大香伊蕉国产www亚洲,男ji大巴进入女人的视频小说,男人把ji大巴放进女人免费视频,免费情侣作爱视频

代理加盟

2023全新代理計劃,一站式模板建站,銅牌代理低至699元送終身VIP,獨立代理后臺,自營貼牌。

您現(xiàn)在的位置: 麥站網(wǎng) > 站長學(xué)院 > 帝國教程 >

帝國CMS模板調(diào)用購物車商品數(shù)量和總價

來源:本站原創(chuàng) 發(fā)布時間:2020-07-01 08:48:26熱度: ℃我要評論(0

麥站模板建站平臺(10年經(jīng)驗),服務(wù)數(shù)萬家企業(yè),固定透明報價。域名注冊、主機/服務(wù)器、網(wǎng)站源碼一站式服務(wù)。實體公司,專業(yè)團隊,值得選擇!超過1000套模板已登記版權(quán),合規(guī)合法建站,規(guī)避版權(quán)風(fēng)險!【點擊獲取方案】

<?php

/**
 * 根據(jù)Cookie值對購物車商品數(shù)量和總價格調(diào)用
 */
 require("class/connect.php");
 
 $totalProducts = 0;    //購物車商品總數(shù)
 $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];            //當(dāng)前商品的數(shù)量
         $thisId = explode(",",$priceAndNumber[1]);
         $thisId = $thisId[1];                    //當(dāng)前商品的ID
         $thisPrice = this_price($thisId);        //當(dāng)前商品價格
         
         $totalPrice += $thisPrice * $thisNum;    //購物車商品總價累加
         $totalProducts += $thisNum;                //購物車商品總數(shù)累加
     }
     
     echo "document.write("".displayResultJs($totalPrice,$totalProducts)."")";    //顯示結(jié)果Js形式輸出
     
 }catch (Exception $e){
     echo $e->getMessage();
 }
 
 
 /**計算商品價格*/
 function this_price($id){
     $connect = connectDB();
     $query = "select price from phome_ecms_news where id = ".$id;
     if(!$connect){
        throw new Exception("數(shù)據(jù)庫鏈接不成功,請檢查!");
     }
     if(!$result = $connect -> query($query)){
         throw new Exception("查詢失敗!");
     }
     $row = $result -> fetch_assoc();
     
     return $row['price'];
 }
 
 /**鏈接數(shù)據(jù)庫*/
 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;
 }
 
 /**顯示結(jié)果Js*/
 function displayResultJs($totalPrice,$totalProducts){
     return "<div class='car'>您的購物車中有 {$totalProducts} 件商品,總計金額 ¥{$totalPrice}元。<br />點擊查看   <a href='/e/ShopSys/buycar/'>結(jié)算&gt;&gt;</a> </div>";
 }
?>

 

    轉(zhuǎn)載請注明來源網(wǎng)址:http://mengdiqiu.com.cn/empire_cms/2478.html

    發(fā)表評論

    評論列表(條)

       
      QQ在線咨詢
      VIP限時特惠