php購物車實現代碼(1/2)

來源:互聯網
上載者:User

些購物車會用到php檔案
 main.php 顯示商品
 additem.php把商品加入購物車
 cearcart.php刪除購物車中的商品
 shoppingcart.php 操作類
 
使用者的資料庫教程有

 代碼如下 複製代碼
 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)
  );
  insert into inventory values ('硬碟','5','1','80g','5600','1');
  insert into inventory values ('cpu','12','2','p4-2.4g','6600','1');
  insert into inventory values ('dvd-rom','7','3','12x','2000','1');
  insert into inventory values ('主板www.111cn.net','3','4','asus','5000','2');
  insert into inventory values ('顯示卡','6','5','64m','4500','1');
  insert into inventory values ('燒錄機','4','6','52w','3000','1');
 
 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)
  );
 shopper
 
  create database shopper;
  use shopper;
  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)
  );
  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)
  );
  insert into inventory values ('硬碟','5','1','80g','5600','1');
  insert into inventory values ('cpu','12','2','p4-2.4g','6600','1');
  insert into inventory values ('dvd-rom','7','3','12x','2000','1');
  insert into inventory values ('主板111cn.net','3','4','asus','5000','2');
  insert into inventory values ('顯示卡','6','5','64m','4500','1');
  insert into inventory values ('燒錄機','4','6','52w','3000','1');

*/

//main.php 顯示購物車所有商品

 代碼如下 複製代碼

include("shoppingcart.php");
$cart = new cart;
$table="shopping";

/* 查詢並顯示所有存貨表中的資訊 */
    $query = "select * from inventory";
    $invresult = mysql教程_query($query);
    if (!($invresult)) {
       echo "查詢失敗<br>";
       exit;
    }
    echo "以下產品可供訂購∶";
    echo "<table border=0>";
    echo "<tr><td bgcolor=#aaccff>產品編號</td><td bgcolor=#aaccff>產品名稱</td><td bgcolor=#aaccff>單價</td>";
    echo "<td bgcolor=#aaccff>剩餘數量</td><td bgcolor=#aaccff>產品描述</td><td bgcolor=#aaccff>放入購物車</td></tr>";
    while($row_inventory = mysql_fetch_object($invresult)) {
    echo "<tr><td bgcolor=#aaccff>".$row_inventory->id."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->product."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->price."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->quantity."</td>";
    echo "<td bgcolor=#aaccff>".$row_inventory->description."</td>";
    echo "<td bgcolor=#aaccff><a href='additem.php?product=".$row_inventory->product."'><img border='0' src='cart.gif' width='81' height='17'></a></td></tr>";
    }
    echo "</table>";
    echo "<br>購物車中產品的數量∶".$cart->quant_items($table, $session);
    echo "<br><br><a href='clearcart.php'><img border='0' src='car.gif'></a>清空購物車";

 

首頁 1 2 末頁

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.