免费一级码无码婬片AA,多姿,国产成人精品日本亚洲18图 ,亚洲欧美视频一区,久久久久国产精品一区

做網站找實速,專業網站制作設計平臺
首頁 > 課堂 > 網站技術 > 詳情
網站標簽 / Tags

深入帝國CMS調用購物車商品數量和總價的方法

2020-02-16 15:40:34   來源:實速網絡|網站建設|網站設計|網站優化|網站仿制|網站SEO|網站推廣|空間域名|主機VPS|服務器|網站源碼|網站模版   瀏覽: 次
深入帝國CMS調用購物車商品數量和總價的方法 發布時間:2019-12-05 來源:未知 瀏覽: 關鍵詞:帝國CMS

深入帝國CMS調用購物車商品數量和總價的方法

發布時間:2019-12-05 來源:未知 瀏覽: 關鍵詞:帝國CMS 

深入帝國CMS調用購物車商品數量和總價的方法

本文實例講述了帝國CMS調用購物車商品數量和總價的方法。分享給大家供大家參考。具體實現方法如下:

代碼如下:

<?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();}/**計算商品價格*/function this_price($id){$connect = connectDB();$query = "select price from phome_ecms_news where id = ".$id;if(!$connect){throw new Exception("數據庫鏈接不成功,請檢查!");}if(!$result = $connect -> query($query)){throw new Exception("查詢失敗!");}$row = $result -> fetch_assoc();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;}/**顯示結果Js*/function displayResultJs($totalPrice,$totalProducts){return "<div class='car'>您的購物車中有 {$totalProducts} 件商品,總計金額 ¥{$totalPrice}元。點擊查看 <a href='/e/ShopSys/buycar/'>結算&gt;&gt;</a> </div>";}?>

推薦學習《帝國cms教程

希望本文所述對大家的帝國CMS建站有所幫助。

以上就是深入帝國CMS調用購物車商品數量和總價的方法的詳細內容,更多請關注魔酷閣其它相關文章!

責任編輯:實速科技