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

歡迎來到入門教程網(wǎng)!

帝國cms

當前位置:主頁 > CMS教程 > 帝國cms >

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

來源:本站原創(chuàng)|時間:2020-01-11|欄目:帝國cms|點擊: 次

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


復制代碼
代碼如下:
<?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]; //當前商品的數(shù)量
$thisId = explode(",",$priceAndNumber[1]);
$thisId = $thisId[1]; //當前商品的ID
$thisPrice = this_price($thisId); //當前商品價格

$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}元。
點擊查看 <a href='/e/ShopSys/buycar/'>結(jié)算&gt;&gt;</a> </div>";
}
?>

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

上一篇:帝國cms7.0動態(tài)列表頁面分頁顯示個數(shù)修改方法

欄    目:帝國cms

下一篇:帝國CMS實現(xiàn)高效隨機調(diào)用的方法

本文標題:帝國CMS調(diào)用購物車商品數(shù)量和總價的方法

本文地址:http://mengdiqiu.com.cn/a1/diguocms/12451.html

網(wǎng)頁制作CMS教程網(wǎng)絡編程軟件編程腳本語言數(shù)據(jù)庫服務器

如果侵犯了您的權(quán)利,請與我們聯(lián)系,我們將在24小時內(nèi)進行處理、任何非本站因素導致的法律后果,本站均不負任何責任。

聯(lián)系QQ:835971066 | 郵箱:835971066#qq.com(#換成@)

Copyright © 2002-2020 腳本教程網(wǎng) 版權(quán)所有