『壹』 如何用html css javascript php製作購物車
一兩句說不清楚………
用html css做出商品樣子和購物車樣子,
然後用javascript來對買這個動專作做處理,把商品的信屬息存起來,通過js把商品信息傳遞給購物車,讓購物車能夠顯示;
另一方面把信息交給php,寫入資料庫。
我這么說你明白了么……
『貳』 設計一個購物車,包含html和php兩個文件,html讓客戶輸入個人信息以及顯示商品信息。php將訂單信息返回給
訂單表,客戶信息表,商品信息表,購物車表存放客戶信息表,商品信息回表的主鍵id,用來關聯答,並且建立一個數量的欄位,用來計算總價。客戶錄入表單去提交頁面添加判斷然後跳轉購物頁,添加購物車的話直接基於數量和兩個主鍵id去添加,下單的話基於時間戳生成訂單編號和客戶編號存放在訂單表中,記得主外鍵關聯
『叄』 如何用html php製作購物車
網上有好多教程你隨便搜一下就有了
『肆』 php購物車 代碼
將你的session,看成一個數組。
$_SESSION['user_id']= array{
['商品id'] = array{
'價格'=>501,
},
['商品id'] = array{
'價格'=>502,
},
['商品id'] = array{
'價格'=>503,
}
}
以上保存了3件商品的信息,專如果用戶id為20的人,期間修改了屬商品的信息,就根據user_id與商品id,去修改你的這個數組,最後生成訂單的時候,insert入庫。
『伍』 php 購物車代碼一般是用什麼方法實現
將你的session,看成抄一個數組。
$_SESSION['user_id']=array{
['商品襲id']=array{
'價格'=>501,
},
['商品id']=array{
'價格'=>502,
},
['商品id']=array{
'價格'=>503,
}
}
以上保存了3件商品的信息,如果用戶id為20的人,期間修改了商品的信息,就根據user_id與商品id,去修改你的這個數組,最後生成訂單的時候,insert入庫。
『陸』 PHP 高手 請進來看下這段購物車代碼
$sql="SELECT name,price FROM proct WHERE id='$id'";
$id是變數,php中雖然雙引號和單引號都能表示字元串,但是不同的內是,單引號不能解析變數,也就容是說'$aaaa'表示的就是字元串$aaaa,而不會解析字元串!
改為:
$sql="SELECT name,price FROM proct WHERE id=$id";
『柒』 php 購物車代碼~呢
<?php
class Shopcar
{
//商品列表
public $proctList=array();
/**
*
* @param unknown_type $proct 傳進來的商品
* @return true 購物車裡面沒有該商品
*/
public function checkProct($proct)
{
for($i=0;$i<count($this->proctList);$i++ )
{
if($this->proctList[$i]['name']==$proct['name'])
return $i;
}
return -1;
}
//添加到購物車
public function add($proct)
{
$i=$this->checkProct($proct);
if($i==-1)
array_push($this->proctList,$proct);
else
$this->proctList[$i]['num']+=$proct['num'];
}
//刪除
public function delete($proct)
{
$i=$this->checkProct($proct);
if($i!=-1)
array_splice($this->proctList,$i,1);
}
//返回所有的商品的信息
public function show()
{
return $this->proctList;
}
}
你可以去後盾人平台看看,裡面的東西不錯
『捌』 用php結合cookie實現購物車的一些問題
URL傳遞的參數可以來在連接後的程序源中直接使用,如:
<a href="zancunjia.php?a1=YF0001&b1=500&c1=8888&d1=YF0001.html ">鏈接1</a><br/>
zancunjia.php中可以用$a1來的到a1,類推……
COOKIE可以使用setcookie()函數設置!
使用已設置的COOKIE是用全局變數:$_COOKIE['***']!***是所設置的鍵值……
如果是購物車,我舉得不應該使用cookie來保存信息,而是要用session,這樣比較好一些!
『玖』 購物車代碼怎麼寫php
寫就行了,跟普通的一樣,不就是資料庫的增刪改查嗎
『拾』 【高分】急求用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 proct 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 <br><hr><br>";
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`)
)
proct 裡面用的ID CLASS1是
`ID` int(6) NOT NULL auto_increment,
`Class1` varchar(20) NOT NULL,
`Price` int(6) NOT NULL,