当前位置:首页 > 代码 > 正文

动态网页购物车源代码(购物车代码实现数据库)

admin 发布:2022-12-19 23:59 150


今天给各位分享动态网页购物车源代码的知识,其中也会对购物车代码实现数据库进行解释,如果能碰巧解决你现在面临的问题,别忘了关注本站,现在开始吧!

本文目录一览:

【高分】急求用php写的购物车代码!!!!!(十万火急)如果您提供的好用还有加分!!!

我也要弄一个这种购物车,

我去写个,贴出来,【嘿嘿,今天上午新写的】。

我懒得新建数据库,用的是我的数据库。

你按照我的改一下就能用了

本人水平有限,高手请指正。

你,大,爷的,虽然不咋地,保证能用

、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、、

经过调试,

//$my-add_cart(45,3,"茶几系列");//新增购物

//$my-updata_cart(13,13,8); //更新购物

//$my-del_cart(12,5,'Guest'); //删除一种购物

//$my-empty_cart('Guest'); //清空购物车

$ok=$my-get_cart('Guest'); //返回购物车

这些都可用

-------------------------------------------------------------------

?php

class Cart

{

public $totalCost=0; //商品总金额

function cart($host,$usr,$pwd,$db)

{

mysql_connect($host,$usr,$pwd) or die(mysql_error);

mysql_select_db($db) or die(mysql_error);

mysql_query("SET Names GBk");

//只要有人访问,就自动清除一天前所有没付款的订单;

$sql="delete FROM shopcart WHERE TO_DAYS( NOW( )) - TO_DAYS( ptime ) =1 and payment=0";

mysql_query($sql);

}

// 弹出提示

function alter($Str,$Url)

{

echo "Script language='JavaScript' alert('".$Str."');/Script";

echo "meta http-equiv=refresh content=0;URL=".$Url."";

}

//增加购物;三个参数:pid:产品ID,ptl:产品数量,pcid:产品类别

//查询数据库,是否存在此人在本日内订过本产品

//如果订过,那么数量累加,否则插入一个数据库行

function add_cart($pid,$ptl=1,$pcid)

{

if($ptl=100 || $ptl=0)

{

$this-alter("最多买99件,最少1件","index.php");

die();

}

if(!$_SESSION['usr']) { $usr='Guest';}

else { $usr=$_SESSION['usr'];}

$sql="select * from shopcart where pid='".$pid."' and usr='".$usr."' and pcid='".$pcid."'";

$ex=mysql_query($sql);

$ex1=mysql_fetch_array($ex);

if(!$ex1)

{

$sql="select * from product where ID='".$pid."' and class1='".$pcid."'";

$ok=mysql_query($sql);

$rs=mysql_fetch_array($ok);

if($rs)

{

$totalCost= $rs['Price'] * $ptl;

$sql="insert into shopcart(usr,pid,pname,ptl,price,pcid,psum,payment) Values(";

$sql.="'".$usr."',";

$sql.="'".$rs['ID']."',";

$sql.="'".$rs['Name']."',";

$sql.="'".$ptl."',";

$sql.="'".$rs['Price']."',";

$sql.="'".$rs['Class1']."',";

$sql.="'".$totalCost."',";

$sql.="'0')";

mysql_query($sql) or die(mysql_error());

if($ok) { $this-alter("购物成功","index.php"); }

else { $this-alter("购物失败","index.php"); }

}

else

{

$this-alter("不存在的商品,或者参数错误","index.php");

die();

}

}

else

{

$sql="update shopcart set ptl= ptl+1,psum = psum+price where ID='".$ex1['ID']."'";

mysql_query($sql);

$this-alter("更新数量成功","index.php");

}

}

//更新购物车的单个产品的数量;

function updata_cart($cid,$ptl,$pid)

{

if($ptl=100||$ptl=0)

{

$this-alter('产品数量不对!','index.php');

die();

}

$sql="select * from shopcart where ID='".$cid."' and pid='".$pid."'";

$ok=mysql_query($sql);

if(!ok) { alter("参数发生错误","index.php");}

else

{

$sql="update shopcart set ptl='".$ptl."',psum=price * '".$ptl."' where ID='".$cid."' and pid='".$pid."'";

$ok=mysql_query($sql);

if(!ok) { $this-alter("更新失败","index.php");}

else { $this-alter("更新成功","index.php");}

}

}

function del_cart($cid,$pid,$usr)

{

$sql="delete from shopcart where usr='".$usr."' and ID='".$cid."' and pid='".$pid."'";

$ok=mysql_query($sql);

if(!$ok) {$this-alter("删除失败","index.php");}

else {$this-alter("删除成功","index.php");}

}

function empty_cart($usr)

{

$sql="delete from shopcart where usr='".$usr."'";

mysql_query($sql) or die(mysql_error);

}

function get_cart($usr)

{

$sql="select * from shopcart where usr='".$usr."'";

$ok=mysql_query($sql);

return $ok;

}

}

$my = new Cart("localhost","root","root","mybbs");

//$my-add_cart(45,3,"茶几系列");

//$my-updata_cart(13,13,8);

//$my-del_cart(12,5,'Guest');

//$my-empty_cart('Guest');

$ok=$my-get_cart('Admin');

echo "usr pid pname ptl price pcid psum payment ptime brhrbr";

while($rs=mysql_fetch_array($ok))

{

echo $rs[1]."-".$rs[2]."-".$rs[3]."-".$rs[4]."-".$rs[5]."-".$rs[6]."-".$rs[7]."-".$rs[8]."-".$rs[9]."br";

}

?

、、、、、、、、、、、、、、、、、SQL、、、、、、、、、、、、、、

CREATE TABLE IF NOT EXISTS `shopcart` (

`ID` int(10) NOT NULL auto_increment,

`usr` varchar(50) NOT NULL,

`pid` int(5) NOT NULL,

`pname` varchar(100) NOT NULL,

`ptl` int(3) NOT NULL,

`price` decimal(50,2) NOT NULL default '0.00',

`pcid` varchar(100) NOT NULL,

`psum` decimal(50,2) NOT NULL default '0.00',

`payment` tinyint(1) NOT NULL,

`ptime` timestamp NOT NULL default CURRENT_TIMESTAMP,

PRIMARY KEY (`ID`)

)

product 里面用的ID CLASS1是

`ID` int(6) NOT NULL auto_increment,

`Class1` varchar(20) NOT NULL,

`Price` int(6) NOT NULL,

购物车的Java代码

import java.util.ArrayList;

import java.util.HashMap;

import java.util.Iterator;public class ShoppingCartManager {

HashMapString, String hm=new HashMapString, String();

float totlePrice=0;

//添加book到购物车

public void addBook(String bookId,String bookQuantity){

if(hm.containsKey(bookId)){

int value=Integer.parseInt(hm.get(bookId));

value+=Integer.parseInt(bookQuantity);

hm.put(bookId, value+"");

}else{

hm.put(bookId, bookQuantity);

}

}

//修改数量

public void updateQuantity(String bookId,String bookQuantity){

hm.put(bookId, bookQuantity);

}

//获取购物车的所有信息 并计算总价

public ArrayListBookBean getShoppingCart(){

ArrayListBookBean al=new ArrayListBookBean();

IteratorString i=hm.keySet().iterator();

String ids="";

BookTableManager btm=new BookTableManager();

while(i.hasNext()){

ids=ids+","+i.next();

}

al= btm.selectByBookIds(ids);

totlePrice=0; //清空总价,防止无限累计

for(int j=0;jal.size();j++){

BookBean bb=al.get(j);

totlePrice+=bb.getPrice()*Integer.parseInt(getQuantityById(bb.getBookId()+""));

}

return al;

}

//获取总价

public float getTotlePrice(){

return totlePrice;

}

//根据ID获取数量

public String getQuantityById(String id){

String quantity=hm.get(id);

return quantity;

}

//清空购物车

public void clear(){

hm.clear();

}

//删除购物车中的一本书

public void deleteById(String id){

hm.remove(id);

}

}

请问asp网页购物车代码中是什么

第一个页面

a href="Payment.asp?Product_Id=%=rs("Product_Id")%",target="_blank"

意思是传值把产品的唯一主键值传给另一个页面接收

在新页面打开文件Payment.asp,并传递参数变量Product_Id的值为rs("Product_Id")

-----------------------------------------

第二个页面:

Session("ProductList") = ProductList 把ProductList 赋值给session

'判断购物车是否为空

if Productlist"''" then ’如果productlist不是空值那么执行下面的语句

sql="select * from Product where Product_Id in ("ProductList") order by Product_Id" ‘sql查询语句赋值给变量sql

Set rs_price = conn.Execute(sql) ’执行sql查询

else ‘如果productlist是空值

response.redirect "error.asp?error=007" ’输出error参数=707的错误页面

response.end ‘结束执行后面的代码

end if ’结束if条件判断

if语句格式

if 条件 then

************** 符合条件的执行代码

else

************** 不符合条件的执行代码

end if 结束if条件语句

求PHP里的TP5的购物车代码

可以参考如下代码

?php

class Cart extends Think {

//当前购物车名

public $sessionName;

//购物车总价格

public $totalPrice

public function __construct($sessionName)

{

$this-sessionName=$sessionName;

if(!isset($_SESSION[$this-sessionName]))

 {

$_SESSION[$this-sessionName]="";

  }

 }

//获取购物车的信息

public function getCart(){

    $cur_cart_array=$_SESSION[$this-sessionName];

    return $cur_cart_array;

}

//获取购物车商品清单

public function getCartList()

{

$cur_cart_array=$_SESSION[$this-sessionName];

if($cur_cart_array!="")

 {

  $mode_goods_data=M("goods_data");

  $len=count($cur_cart_array);

  for($i=0;$i$len;$i++)

  {

  $goodsid=$cur_cart_array[$i]["id"];

  $num=$cur_cart_array[$i]["num"];

   $query="select (select sfilename from goods_pic where goodsid=a.goodsid order by sno desc limit 0,1) as sfilename,b.clsname as clsname,a.goodsid as goodsid,a.goodsname as goodsname,a.Price as Price,a.Storageqty as Storageqty from goods_data a left join goods_cls b on a.Clsid=b.clsid where a.goodsid=$goodsid";

    $list=$mode_goods_data-query($query);

    $list[0]["qty"]=$num;

    $list[0]["amount"]=$num*$list[0]["Price"];

    $cartList[$i]=$list[0];

    $totalPrice+=$list[0]["amount"];

  }

  //返回商品总价格

  $this-totalPrice=$totalPrice;

    return $cartList;

 }

}

//加入购物车,购物车的商品id和购物车的商品数量

public function addcart($goods_id,$goods_num){

      $cur_cart_array=$_SESSION[$this-sessionName];

      if($cur_cart_array=="")

       {

          $cart_info[0]["id"]=$goods_id;//商品id保存到二维数组中

      $cart_info[0]["num"]=$goods_num;//商品数量保存到二维数组中

      $_SESSION[$this-sessionName]=$cart_info;

        }

        else

        {   

          //返回数组键名倒序取最大

      $ar_keys=array_keys($cur_cart_array);

           $len=count($ar_keys);

           $max_array_keyid=$ar_keys[$len-1]+1;

          //遍历当前的购物车数组

     //遍历每个商品信息数组的0值,如果键值为0且货号相同则购物车该商品已经添加

     $is_exist=$this-isexist($goods_id,$goods_num,$cur_cart_array);

         if($is_exist==false)

         {

             $cur_cart_array[$max_array_keyid]["id"] = $goods_id;

             $cur_cart_array[$max_array_keyid]["num"] = $goods_num;

             $_SESSION[$this-sessionName]=$cur_cart_array;

         }

         else

         {

          $arr_exist=explode("/",$is_exist);

          $id=$arr_exist[0];

          $num=$arr_exist[1];

          $cur_cart_array[$id]["num"]=$num;

          $_SESSION[$this-sessionName]=$cur_cart_array;

         } 

       }

}

//判断购物车是否存在相同商品

public function isexist($id,$num,$array)

{

 $isexist=false;

 foreach($array as $key1=$value)

 {

  foreach($value as $key=$arrayid)

  {

    if($key=="id"  $arrayid==$id)

    {

     $num=$value["num"]+$num;

     $isexist=$key1."/".$num;

    }

  }

 }

 return $isexist;

}

thinkphp开发使得我们比较容易的去进行了

//从购物车删除

public function delcart($goods_array_id){

         //回复序列化的数组

     $cur_goods_array=$_SESSION[$this-sessionName];

        //删除该商品在数组中的位置

     unset($cur_goods_array[$goods_array_id]);

         $_SESSION[$this-sessionName]=$cur_cart_array;

         //使数组序列化完整的保存到cookie中

}

//清空购物车

public function emptycart(){

$_SESSION[$this-sessionName]="";

}

//修改购物车货品数量   

public function update_cart($up_id,$up_num){

 //回复序列化的数组

 $cur_goods_array=$_SESSION[$this-sessionName];  

  $cur_goods_array[$up_id]["num"]=$up_num;

  $_SESSION[$this-sessionName]=$cur_cart_array;

}

}

?

求html购物车代码,,效果如图显示

html xmlns=""    

head    

meta http-equiv="Content-Type" content="text/html; charset=gb2312" /    

title修改订单/title    

style type="text/css"    

body{    

font-size:13px;    

line-height:25px;    

}    

table{    

border-top: 1px solid #333;    

border-left: 1px solid #333;    

width:400px;    

}    

td{    

border-right: 1px solid #333;    

border-bottom: 1px solid #333;    

text-align:center;    

}    

.title{

    

font-weight:bold;    

background-color: #cccccc;    

}    

input text{    

width:100px;    

}    

         

/style    

script type="text/javascript"    

function addRow(){    

//行的长度    

var rowlength=document.getElementById("order").rows.length;    

//得到整个表格对象    

var order = document.getElementById("order").insertRow(rowlength-1);    

order.id=rowlength-1;    

//插入列    

var cel1=order.insertCell(0).innerHTML="游戏光盘";    

var cel2=order.insertCell(1).innerHTML="34";    

var cel3=order.insertCell(2).innerHTML="yen;58.40";    

var cel4=order.insertCell(3).innerHTML="input type=\"button\"value=\"删除\" onclick=\"delRow('"+(rowlength-1)+"')\"/"+ "input type=\"button\"value=\"修改\" onclick=\"editRow('"+(rowlength-1)+"')\"/"    

}    

function delRow(qwe){    

var ewq=document.getElementById(qwe).rowIndex;    

document.getElementById("order").deleteRow(ewq);    

}    

function editRow(rowID){    

var row=document.getElementById(rowID);    

var cel=row.cells;    

var text=cel[1].innerHTML;    

cel[1].innerHTML="input type='text' value='"+text+"' style='width:40px;'"    

cel[3].lastChild.value="确定";    

cel[3].lastChild.setAttribute("onclick","update('"+rowID+"')");    

}    

    

function update(qwe){    

var row=document.getElementById(qwe);    

var cel=row.cells;    

var text=cel[1].lastChild.value;    

cel[1].innerHTML=text;    

cel[3].lastChild.value="修改";    

cel[3].lastChild.setAttribute("onclick","editRow('"+qwe+"')");    

}    

/*

    

function add(){    

var a = document.getElementById("order").rows.length;    

var b = document.getElementById("order").insertRow(a-1);    

var one1 = b.insertCell(0).innerHTML="123";    

}    

*/    

/script    

/head    

body    

table border="0" cellspacing="0" cellpadding="0" id="order"    

 tr class="title"    

   td商品名称/td    

   td数量/td    

   td价格/td    

   td操作/td    

 /tr    

 tr id="1"    

   td防滑真皮休闲鞋/td    

   td12/td    

   tdyen;568.50/td    

   tdinput name="rowdel" type="button" value="删除" onclick='delRow("1")' /    

   input id="edit1" type="button" value="修改" onclick='editRow("1")' //td    

 /tr    

 tr    

   td colspan="4" style="height:30px;"    

   input name="addOrder" type="button" value="增加订单" onclick="addRow()" //td    

 /tr    

/table    

/body    

/html

这个是我原来上学的时候练习的代码,练习的是基础的jsDOM操作,不过建议以后用Jquery 比较方便  有什么不懂得可以问我

关于动态网页购物车源代码和购物车代码实现数据库的介绍到此就结束了,不知道你从中找到你需要的信息了吗 ?如果你还想了解更多这方面的信息,记得收藏关注本站。

版权说明:如非注明,本站文章均为 AH站长 原创,转载请注明出处和附带本文链接;

本文地址:http://ahzz.com.cn/post/31374.html


取消回复欢迎 发表评论:

分享到

温馨提示

下载成功了么?或者链接失效了?

联系我们反馈

立即下载