PHP教程.应用实例_PHP
PHP/MySQL 购物车程序
if(!$session && !$scid) {
$session = md5(uniqid(rand()));
SetCookie("scid", "$session", time() + 14400);
} /* last number is expiration time in seconds, 14400 sec = 4 hrs */
class Cart {
function check_item($table, $session, $product) {
$query = "SELECT * FROM $table WHERE session='$session' AND product='$product' ";
$result = mysql_query($query);
if(!$result) {
return 0;
}
$numRows = mysql_num_rows($result);
if($numRows == 0) {
return 0;
} else {
$row = mysql_fetch_object($result);
return $row->quantity;
}
}
function add_item($table, $session, $product, $quantity) {
$qty = $this->check_item($table, $session, $product);
if($qty == 0) {
$query = "INSERT INTO $table (session, product, quantity) VALUES ";
$query .= "('$session', '$product', '$quantity') ";
mysql_query($query);
} else {
$quantity += $qty;
$query = "UPDATE $table SET quantity='$quantity' WHERE session='$session' AND ";
$query .= "product='$product' ";
mysql_query($query);
}
}
function delete_item($table, $session, $product) {
$query = "DELETE FROM $table WHERE session='$session' AND product='$product' ";
mysql_query($query);
}
function modify_quantity($table, $session, $product, $quantity) {
$query = "UPDATE $table SET quantity='$quantity' WHERE session='$session' ";
$query .= "AND product='$product' ";
mysql_query($query);
}
function clear_cart($table, $session) {
$query = "DELETE FROM $table WHERE session='$session' ";
mysql_query($query);
}
function cart_total($table, $session) {
$query = "SELECT * FROM $table WHERE session='$session' ";
$result = mysql_query($query);
if(mysql_num_rows($result) > 0) {
while($row = mysql_fetch_object($result)) {
$query = "SELECT price FROM inventory WHERE product='$row->product' ";
$invResult = mysql_query($query);
$row_price = mysql_fetch_object($invResult);
$total += ($row_price->price * $row->quantity);
}
}
return $total;
}
function display_contents($table, $session) {
$count = 0;
$query = "SELECT * FROM $table WHERE session='$session' ORDER BY id ";
$result = mysql_query($query);
while($row = mysql_fetch_object($result)) {
$query = "SELECT * FROM inventory WHERE product='$row->product' ";
$result_inv = mysql_query($query);
$row_inventory = mysql_fetch_object($result_inv);
$contents["product"][$count] = $row_inventory->product;
$contents["price"][$count] = $row_inventory->price;
$contents["quantity"][$count] = $row->quantity;
$contents["total"][$count] = ($row_inventory->price * $row->quantity);
$contents["description"][$count] = $row_inventory->description;
$count++;
}
$total = $this->cart_total($table, $session);
$contents["final"] = $total;
return $contents;
}
function num_items($table, $session) {
$query = "SELECT * FROM $table WHERE session='$session' ";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
return $num_rows;
}
function quant_items($table, $session) {
$quant = 0;
$query = "SELECT * FROM $table WHERE session='$session' ";
$result = mysql_query($query);
while($row = mysql_fetch_object($result)) {
$quant += $row->quantity;
}
return $quant;
}
}
?>
/*
This part contains a description of how to create the tables on your mysql server.
# MySQL dump 6.0
#
# Host: localhost Database: kmartShopper
#--------------------------------------------------------
# Server version 3.22.25
#
# Table structure for table 'inventory'
#
CREATE TABLE inventory (
product tinytext NOT NULL,
quantity tinytext NOT NULL,
id int(4) DEFAULT '0' NOT NULL auto_increment,
description tinytext NOT NULL,
price float(10,2) DEFAULT '0.00' NOT NULL,
category char(1) DEFAULT ' NOT NULL,
KEY id (id),
PRIMARY KEY (id),
KEY price (price)
);
#
# Table structure for table 'shopping'
#
CREATE TABLE shopping (
session tinytext NOT NULL,
product tinytext NOT NULL,
quantity tinytext NOT NULL,
card tinytext NOT NULL,
id int(4) DEFAULT '0' NOT NULL auto_increment,
KEY id (id),
PRIMARY KEY (id)
);
*/
Example
include("shoppingcart.php");
$cart = new Cart;
$mysql_link = mysql_connect("localhost", "wwwrun", "");
$mysql_select_db("kmartShopper", $mysql_link) /* heh, use whatever database name you put the 2 tables under in place of kmartShopper */
?>
/* call functions like $cart->add_item and such, see the code. */

熱AI工具

Undresser.AI Undress
人工智慧驅動的應用程序,用於創建逼真的裸體照片

AI Clothes Remover
用於從照片中去除衣服的線上人工智慧工具。

Undress AI Tool
免費脫衣圖片

Clothoff.io
AI脫衣器

Video Face Swap
使用我們完全免費的人工智慧換臉工具,輕鬆在任何影片中換臉!

熱門文章

熱工具

記事本++7.3.1
好用且免費的程式碼編輯器

SublimeText3漢化版
中文版,非常好用

禪工作室 13.0.1
強大的PHP整合開發環境

Dreamweaver CS6
視覺化網頁開發工具

SublimeText3 Mac版
神級程式碼編輯軟體(SublimeText3)

得物APP是當前十分火爆品牌購物的軟體,但是多數的用戶不知道得物APP中功能如何的使用,下方會整理最詳細的使用教程攻略,接下來就是小編為用戶帶來的得物多功能使用教學匯總,有興趣的用戶快來一起看看吧!得物使用教學【2024-03-20】得物分期購怎麼使用【2024-03-20】得物優惠券怎麼獲得【2024-03-20】得物人工客服怎麼找【2024-03-20】得物取件碼怎麼查看【2024-03-20】得物求購在哪裡看【2024-03-20】得物vip怎麼開【2024-03-20】得物怎麼申請退換貨

從主畫面中刪除了重要內容並試圖將其取回?您可以透過多種方式將應用程式圖示放回螢幕。我們已經討論了您可以遵循的所有方法,並將應用程式圖示放回主畫面如何在iPhone中撤消從主畫面中刪除正如我們之前提到的,有幾種方法可以在iPhone上恢復此變更。方法1–替換應用程式庫中的應用程式圖示您可以直接從應用程式庫將應用程式圖示放置在主畫面上。步驟1–橫向滑動以尋找應用程式庫中的所有應用程式。步驟2–找到您先前刪除的應用程式圖示。步驟3–只需將應用程式圖示從主庫拖曳到主畫面上的正確位置即可。這是將應用程式圖

PHP中箭頭符號的作用及實踐應用在PHP中,箭頭符號(->)通常用於存取物件的屬性和方法。物件是PHP中物件導向程式設計(OOP)的基本概念之一,在實際開發中,箭頭符號在操作物件時發揮重要作用。本文將介紹箭頭符號的作用以及實踐應用,並提供具體的程式碼範例來幫助讀者更好地理解。一、箭頭符號的作用存取物件的屬性箭頭符號可以用來存取物件的屬性。當我們實例化一個對

夏天雨後,常常能見到美麗又神奇的特殊天氣景象-彩虹。這也是攝影中可遇而不可求的難得景象,非常出片。彩虹出現有這樣幾個條件:一是空氣中有充足的水滴,二是太陽以較低的角度照射。所以下午雨過天晴後的一段時間內,是最容易看到彩虹的時候。不過彩虹的形成受天氣、光線等條件的影響較大,因此一般只會持續一小段時間,而最佳觀賞、拍攝時間更為短暫。那麼遇到彩虹,怎樣才能合理地記錄下來並拍出質感呢? 1.尋找彩虹除了上面提到的條件外,彩虹通常出現在陽光照射的方向,即如果太陽由西向東照射,彩虹更有可能出現在東

隨著智慧型手機的不斷發展,手機的功能也變得越來越強大,其中截長圖功能成為了許多用戶日常使用的重要功能之一。截長圖可以幫助使用者將較長的網頁、對話記錄或圖片一次儲存下來,方便查閱和分享。而在眾多手機品牌中,華為手機也是備受用戶推崇的一款品牌之一,其截長圖功能也備受好評。本文將為大家介紹華為手機截長圖的正確方法,以及一些專家技巧,幫助大家更好地利用華為手機的

PHP教學:如何將int型別轉換為字串在PHP中,將整型資料轉換為字串是常見的操作。本教學將介紹如何使用PHP內建的函數將int型別轉換為字串,同時提供具體的程式碼範例。使用強制型別轉換:在PHP中,可以使用強制型別轉換的方式將整型資料轉換為字串。這種方法非常簡單,只需要在整型資料前加上(string)即可將其轉換為字串。下面是一個簡單的範例程式碼

Go語言是一種由Google開發的開源程式語言,於2007年首次發布。它被設計成一種簡單易學、高效、並發性強的語言,受到越來越多開發者的青睞。本文將探討Go語言的優勢,並介紹一些適合Go語言的應用場景,同時給出具體的程式碼範例。優勢並發性強:Go語言內建支援輕量級執行緒-goroutine,能夠輕鬆實現並發程式設計。透過使用go關鍵字就可以啟動goroutin
