if(!$session && !$scid) {
$session = md5(uniqid(rand()));
SetCookie("scid", "$session", time() + 14400);
} /* 最後の数字は秒単位の有効期限、14400 秒 = 4 時間 */
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);
$row->数量を返します。
}
}
function add_item($table, $session, $product, $quantity) {
$qty = $this-> check_item($table, $session, $product);
if($qty == 0) {
$query = "$table (セッション、製品、数量) の値に挿入 ";
$query .= "('$session', '$product', '$quantity') ";
mysql_query($query);
} else {
$数量 += $数量;
$query = "UPDATE $table SET数量='$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 SETquantity='$quantity' WHEREセッション='$セッション' ";
$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在庫からの価格 WHERE product='$row->product' ";
$invResult = mysql_query($query);
$row_price = mysql_fetch_object($invResult);
$total += ($row_price->価格 * $row->数量);
}
}
$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->価格;
$contents["数量"][$count] = $row->数量;
$contents["total"][$count] = ($row_inventory->価格 * $row->数量);
$contents["description"][$count] = $row_inventory->description;
$count++;
}
$total = $this->cart_total($table, $session);
$contents["final"] = $total;
$content を返します。
}
function num_items($table, $session) {
$query = "SELECT * FROM $table WHERE session='$session' ";
$result = mysql_query($query);
$num_rows = mysql_num_rows($result);
$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;
}
$quant を返します。
}
}
?>
/*
この部分には、mysql サーバー上にテーブルを作成する方法の説明が含まれています。
# MySQL ダンプ 6.0
#
# ホスト: localhost データベース: kmartShopper
#---- -------------------------------------------------- --
# サーバーバージョン 3.22.25
#
# テーブル「inventory」のテーブル構造
#
CREATE TABLE inventory (
product tinytext NOT NULL、 量
tinytext NOT NULL、 id
int(4) DEFAULT '0' NOT NULL auto_increment、 説明
tinytext NOT NULL、 price float(10,2) DEFAULT '0.00' NOT NULL、
category char(1) DEFAULT '' NOT NULL、
KEY id (id)、
主キー (id)、
KEY 価格 (価格)
);
#
# テーブル 'shopping' のテーブル構造
#
CREATE TABLE shopping (
session
tinytext NOT NULL, product
tinytext NOT NULL、 数量
tinytext NOT NULL、 カード
tinytext NOT NULL、 id
int(4) デフォルト'0' NOT NULL auto_increment、 KEY id (id)、
PRIMARY KEY (id)
);
*/
例
include("shoppingcart.php"); $cart = 新しいカート;
$
mysql_link = mysql_connect("localhost", "wwwrun", ""); $
mysql_select_db("kmartShopper", $mysql_link) /* へー、2 つのテーブルに付けたデータベース名を使用してくださいkmartShopper の代わりに */ ?>
/* $cart->
add_item などの関数を呼び出します。コードを参照してください。 */

ホットAIツール

Undresser.AI Undress
リアルなヌード写真を作成する AI 搭載アプリ

AI Clothes Remover
写真から衣服を削除するオンライン AI ツール。

Undress AI Tool
脱衣画像を無料で

Clothoff.io
AI衣類リムーバー

AI Hentai Generator
AIヘンタイを無料で生成します。

人気の記事

ホットツール

SublimeText3 中国語版
中国語版、とても使いやすい

SublimeText3 Mac版
神レベルのコード編集ソフト(SublimeText3)

SecLists
SecLists は、セキュリティ テスターの究極の相棒です。これは、セキュリティ評価中に頻繁に使用されるさまざまな種類のリストを 1 か所にまとめたものです。 SecLists は、セキュリティ テスターが必要とする可能性のあるすべてのリストを便利に提供することで、セキュリティ テストをより効率的かつ生産的にするのに役立ちます。リストの種類には、ユーザー名、パスワード、URL、ファジング ペイロード、機密データ パターン、Web シェルなどが含まれます。テスターはこのリポジトリを新しいテスト マシンにプルするだけで、必要なあらゆる種類のリストにアクセスできるようになります。

Dreamweaver Mac版
ビジュアル Web 開発ツール

PhpStorm Mac バージョン
最新(2018.2.1)のプロフェッショナル向けPHP統合開発ツール
