日韩天天综合网_野战两个奶头被亲到高潮_亚洲日韩欧美精品综合_av女人天堂污污污_视频一区**字幕无弹窗_国产亚洲欧美小视频_国内性爱精品在线免费视频_国产一级电影在线播放_日韩欧美内地福利_亚洲一二三不卡片区

php購物車實(shí)現(xiàn)方法_PHP教程

編輯Tag賺U幣
教程Tag:暫無Tag,歡迎添加,賺取U幣!

推薦:PHP實(shí)現(xiàn)格式化文件數(shù)據(jù)大小顯示的方法
這篇文章主要介紹了PHP實(shí)現(xiàn)格式化文件數(shù)據(jù)大小顯示的方法,通過一個(gè)自定義函數(shù)實(shí)現(xiàn)針對(duì)文件大小的精確格式化,具有一定的參考借鑒價(jià)值,需要的朋友可以參考下 本文實(shí)例講述了PHP實(shí)現(xiàn)格式化文件數(shù)據(jù)大小顯示的方法。分享給大家供大家參考。具體分析如下: 有時(shí)候我們需要在

 這篇文章主要介紹了php購物車實(shí)現(xiàn)方法,通過4個(gè)文件實(shí)現(xiàn)購物車的功能,且使用txt文件保存購物車內(nèi)容,簡單實(shí)用,需要的朋友可以參考下

   

本文實(shí)例講述了php購物車實(shí)現(xiàn)方法。分享給大家供大家參考。具體分析如下:

這里我們?yōu)槟闾峁﹤(gè)簡單的php購物車代碼,從增加購物產(chǎn)品與發(fā)生購買了,在商城開發(fā)中,這個(gè)功能是少不了的,我們不需要數(shù)據(jù)庫,用了txt文本文件來操作用戶購物的內(nèi)容.

增加商品到購物車,代碼如下:

代碼如下: <?php
//
// add_item.php:
// Add an item to the shopping cart.
//
session_start();
if (session_is_registered('cart')) {
session_register('cart');
}

require 'lib.inc.php'; // LoadProducts()

LoadProducts(); // Load products in $master_products_list

// Make $curr_product global
$curr_product = array();

// Loop through all the products and pull up the product
// that we are interested in

foreach ($master_products_list as $prod_id => $product) {
if (trim($prod_id) == trim($_GET[id])) {
$curr_product = $product;
}
}

// Register our session
//session_register('cart');
//if(session_is_registered('cart')) echo "已經(jīng)注冊(cè)";

if ($_POST[ordered]) { // If they have chosen the product

array_push($_SESSION[cart][products], array(trim($_POST[id]), $_POST[quantity]));
$_SESSION[cart][num_items] += $_POST[quantity];
}
?>
<html>
<head>
<title>
<?php if ($_POST[ordered]) { ?>
已經(jīng)添加 <?php echo $curr_product[name]; ?> 到您的購物籃
<?php } else { ?>
添加 <?php echo $curr_product[name]; ?> 到您的購物籃
<?php } ?>
</title>
</head>
<body>
<?php if ($_POST[ordered]) { ?>
<h1><?php echo $curr_product[name]; ?>
添加至購物籃成功</h1>

<a href="cart.php">返回</a> 商品列表頁面.
<?php } else { ?>
<h1>添加 <?php echo $curr_product[name]; ?> 到您的購物籃</h1>

<form action="<?php echo $PHP_SELF; ?>" method="post">
商品名稱: <?php echo $curr_product[name]; ?>
<br>
商品說明: <?php echo $curr_product[desc]; ?>
<br>
商品單價(jià): RMB<?php echo $curr_product[price]; ?>
<br>
商品數(shù)量: <input type="text" size="7" name="quantity">
<input type="hidden" name="id" value="<?php echo $_GET[id]; ?>">
<input type="hidden" name="ordered" value="1">
<input type="submit" value="添加至購物欄">
</form>
<?php } ?>
</body>
</html>

 

查看購物車的商品,代碼如下:

代碼如下: <?php
//
// cart.php:
//
session_start();

require 'lib.inc.php';
//判斷購物籃會(huì)話變量cart是否注冊(cè),不注冊(cè)則注冊(cè)cart變量
if (session_is_registered('cart')) {
session_register('cart');
}

// 如果購物籃沒有初始化,則初始化購物籃
if (!isset($_SESSION[cart][num_items])) {
$_SESSION[cart] = array("num_items" => 0,
"products" => array());
}
// From site_lib.inc, Loads the $master_products_list array
LoadProducts(); //載入物品列表
?>
<html>
<head>
<title>演示會(huì)話跟蹤的購物籃程序</title>
</head>

<body>

<h1>歡迎進(jìn)入網(wǎng)上商店</h1>

<?php
if ($_SESSION[cart][num_items]) { // If there is something to show
?>
<h2>當(dāng)前在購物籃里的物品</h2>
<br>
<table border="2" cellpadding="5" cellspacing="2">
<tr>
<th>
商品名稱
</th>
<th>
商品說明
</th>
<th>
單價(jià)
</th>
<th>
數(shù)量
</th>
<th>

</th>
</tr>
<?php

// Loop through the products
foreach ($_SESSION[cart][products] as $i => $product) {
$product_id = $product[0];
$quantity = $product[1];

$total += $quantity *
(double)$master_products_list[$product_id][price];
?>
<tr>
<td>
<?php echo $master_products_list[$product_id][name]; ?>
</td>
<td>
<?php echo $master_products_list[$product_id][desc]; ?>
</td>
<td>
<?php echo $master_products_list[$product_id][price]; ?>
</td>
<td>
<form action="change_quant.php" method="post">
<input type="hidden" name="id" value="<?php echo $i; ?>">
<input type="text" size="3" name="quantity"
value="<?php echo $quantity; ?>">
</td>
<td>
<input type="submit" value="數(shù)量更改">
</form>
</td>
</tr>
<?php
}
?>
<tr>
<td colspan="2" ALIGN="right">
<b>合計(jì): </b>
</td>
<td colspan="2">
RMB:<?php echo $total; ?>
</td>
<td> </td>
</tr>
</table>
<br>
<br>
<?php
}
?>

<h2>商店待出售的商品</h2>
<br>
<i>
我們提供以下商品待售:
</i>
<br>
<table border="2" cellpadding="5" cellspacing="2">
<tr>
<th>
商品名稱
</th>
<th>
商品說明
</th>
<th>
單價(jià)
</th>
<th>

</th>
</tr>
<?php
// Show all of the products
foreach ($master_products_list as $product_id => $item) {
?>
<tr>
<td>
<?php echo $item[name]; ?>
</td>
<td>
<?php echo $item[desc]; ?>
</td>
<td>
$<?php echo $item[price]; ?>
</td>
<td>
<a href="add_item.php?id=<?php echo $product_id; ?>">
添加至購物籃
</a>
</td>
</tr>
<?php
}

?>
</table>

 

分享:php自定義加密與解密程序?qū)嵗?/a>
這篇文章主要介紹了php自定義加密與解密程序,實(shí)例分析了自定義加密解密類文件及相關(guān)用法,具有一定參考借鑒價(jià)值,需要的朋友可以參考下 本文實(shí)例講述了php自定義加密與解密程序。分享給大家供大家參考。具體分析如下: PHP3 Cryption是一個(gè)非常容易被破解,不安全的加密功

共2頁上一頁12下一頁
來源:模板無憂//所屬分類:PHP教程/更新時(shí)間:2015-03-30
相關(guān)PHP教程