帝國CMS模板調用購物車商品數量和總價建站知識
導讀:1建站知識帝國CMS模板網下面的帝國CMS教程欄目為您提供了帝國CMS模板調用購物車商品數量和總價營銷型網站建設網seo優化趨勢。
<?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 Exce網站建設公司ption("數據庫鏈接不成功,請檢查!"); } if(!$result = $connect -> query($query)){ throw new Exception("查詢失敗!"); } $row = $result -&g建設網站公司t; 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}元。<br />點擊查看 <a href='/e/ShopSys/buycar/'>結算>&網站seo優化培訓gt;</a> </div>"; }?>
相關營銷型網站建設網seo優化趨勢。
聲明: 本文由我的SEOUC技術文章主頁發布于:2023-05-22 ,文章帝國CMS模板調用購物車商品數量和總價建站知識主要講述帝國,總價,CMS網站建設源碼以及服務器配置搭建相關技術文章。轉載請保留鏈接: http://www.bifwcx.com/article/web_4366.html