您的位置:百味书屋 > 范文大全 > 经典范文 > php,购物车完整实现代码 正文

php,购物车完整实现代码

2017-01-14 06:26:30 来源网站: 百味书屋

篇一:PHP功能实现:PHP购物车的构思

PHP功能实现:PHP购物车的构思

网站开发万变不离其宗-离不开“增删改查”,购物车也一样,今日本人就不揣浅陋,谈谈自己对购物车的一些浅薄看法。

一个简单的电子商务平台,只要满足以下几个方面就可以:

1、商品有分类列表展示

2、用户可以浏览并且选择商品–也就是把商品放入购物车

3、用户结算

关于数据库的设计

1、商品表,当然有商品名称、价格、分类、上架日期、存货、是否下架等基础信息

2、用户表,有用户id、联系方式、注册日期等

3、购物车表,有购物车id,用户id,商品id,物品数量、是否结算、是否取消等,根据商品id关联商品表,再结算时计算总价格

4、用户消费表,有id,用户id,消费金额,消费日期等

基本上就是这些,还有什么其他的功能可以再另行设计数据库

支付接口,就用支付宝即可,也可以用其他的,或者用多种,支付宝接口如何使用? 这个在支付宝的官方网站有API使用说明,实在没什么难的。

当然我这里说的只是最基本的购物车功能,但是复杂总是建立在基础之上的,所以,希望那些每天把购物车挂在嘴边的人,最好说明白购物车到底难在哪里,也许对你来说很难的事情,在别人眼里却很简单!

篇二:韩顺平我的购物车开发流程php版

韩顺平php购物车开发流程

需求分析

a. 用户可以登录

b. 用户可以购买商品

c. 用户可以对购物车的商品进行修改和删除

d. 用户可以下订单

e. 系统可以发送电子邮件给用户

uml图

1. 界面设计

登录页面

购物大厅

我的购物车

预览订单

提交订单

? 设计数据库和表

? Create database shopping;

1. 用户表

create table users

(

id int primary key not null,

name varchar(64) not null default '',

pwd char(32) not null default '',

email varchar(128) not null default '',

tel varchar(32) not null default '',

grade tinyint unsigned not null default 1

)

--测试数据

insert into users values(100,'jerry','md5(110)','jerry@qq.com','10086',1);

insert into users values(101,'kate','md5(110)','kate@qq.com','10010',1);

说明 :md5 校验,保存字符为32位。定长,所以用char

2. 商品表

--商品表

create table book

(

id int primary key auto_increment, /*--书的编号*/

name varchar(64) not null default '', /*--书的名字*/

author varchar(64) not null default '',/*--书的作者*/

publishHouse varchar(128) not null default '',/*--出版社*/

price float not null default 0,/*--价格*/

nums int not null default 1000 /*--库存*/

)

--测试数据

insert into book (name,author,publishhouse,price,nums) values('jsp 应用开发详解','萧峰','电子工业出版社', 59, 100 );

insert into book (name,author,publishhouse,price,nums) values('Java Web 服务开发','谭美君','电子工业出版社', 45, 100 );

insert into book (name,author,publishhouse,price,nums) values('Java 编程思想','小红', '机械工业出版社', 99, 100);

insert into book (name,author,publishhouse,price,nums) values('JSP编程指南','王芳','电子工业出版社' ,10, 1000 );

insert into book (name,author,publishhouse,price,nums) values('J2EE1.4应用开发详解','小建', '电子工业出版社', 68, 1000);

insert into book (name,author,publishhouse,price,nums) values('J2EE企业级应用开发','小费', '电子工业出版社',56, 1000 );

insert into book (name,author,publishhouse,price,nums) values('J2EE参考手册','小星','电子工业出版社', 56, 1000 );

insert into book (name,author,publishhouse,price,nums) values('J2EE Web服务开发','顺平','电子工业出版社', 550, 10000 );

3. 购物车表

create table mycart

(

id int unsigned primary key auto_increment, userid int,

bookid int,

nums int unsigned,

carDate int unsigned,

foreign key (userid) references users(id), foreign key (bookid) references book(id) )

篇三:php购物车

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

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

<title>无标题文档</title>

</head>

<body>

<p>

<?php

$conn = @mysql_connect("localhost","root","123456") or die("错误:".error());

mysql_select_db("shopdb",$conn);

mysql_query("SET NAMES GB2312");

?>

<?php

$pagesize=2;

$sql1="select * from shopdb" ;

$result1=mysql_query($sql1);

$num=mysql_num_rows($result1);

if(!$_REQUEST[page])

$page=1;

else

{

$page=$_REQUEST[page];

}

?>

<?PHP

$tem=($page-1)*$pagesize;

$sql="select * from shopdb limit $tem,$pagesize";

$result=mysql_query($sql);

?>

</p>

<table width="200" border="1">

<tr>

<?php while($rows=mysql_fetch_array($result))

{

print_r($rows);?>

<td>

<table width="191" border="1">

<tr>

<td width="48">商品</td>

<td width="127" height="20"><?php echo $rows["sp"] ;?></td>

</tr>

<tr>

<td>价格</td>

<td height="20"><?php echo $rows["jg"] ;?></td>

</tr>

<tr>

<td colspan="2"><div align="center"><a

$rows["id"] ;?>">购买</a></div></td>

</tr> href="fygm.php?id=<?php echo

<tr>

<td height="28" colspan="2"><div align="center"><a href="fygwc.php">购物车</a></div></td>

</tr>

</table></td>

<?php }?>

</tr>

</table>

<p> <?php

$p_count=ceil($num/$pagesize);

$pre=$page-1;

$next=$page+1;

if($page<=1)

{

echo "第一页|";

}

else

{

echo "<a href='$_SERVER[PHP_SELF]?page=1'>第一页</a>|";

}

if($pre<1)

{

echo "上一页|";

}

else

{

echo "<a href='$_SERVER[PHP_SELF]?page=$pre'>上一页</a>|";

}

if($next>$p_count)

{

echo "下一页|";

}

else

{

echo "<a href='$_SERVER[PHP_SELF]?page=$next'>下一页</a>|";

}

if($next>=$p_count)

{

echo "尾页|";

}

else

{

echo "<a href='$_SERVER[PHP_SELF]?page=$p_count'>尾页</a>|";

}

?></p>

<p>&nbsp;</p>

</body>

</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0

"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

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

<title>无标题文档</title>

</head>

<body>

<?php

session_start();

session_register("sid");

session_register("sum");

$sid=$_GET["id"];

if($_SESSION["sid"]=="" && $_SESSION["sum"]==""){

$_SESSION["sid"]=$sid."@";

$_SESSION["sum"]="1@";

}

else

{

$array=explode("@",$_SESSION["sid"]);

if(in_array($sid,$array))

{

echo "<script>alert('存在!');history.back(-1);</script>";

exit;

} Transitional//EN"

$_SESSION["sid"].=$sid."@";

$_SESSION["sum"].="1@";

}

echo "<script>window.location.href='fygwc.php';</script>";

?>

</body>

</html>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

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

<title>无标题文档</title>

</head>

<body>

<?php

session_start();

$id=$_GET["id"];

$arrayid=explode("@",$_SESSION["sid"]);

$arraynum=explode("@",$_SESSION["sum"]);

$key=array_search($id,$arrayid);

$arrayid[$key]="";

$arraynum[$key]="";

$_SESSION["sid"]=implode("@",$arrayid);

$_SESSION["sum"]=implode("@",$arraynum);

echo "<script>window.location.href='fygwc.php';</script>";

?>

</body>

</html>

没有摆渡的金币了..所以贴自己研究的购物车代码..布解释,如果有不明白的想了解的可以加本人qq571451370 前提是你必须下载这个文档


php,购物车完整实现代码》出自:百味书屋
链接地址:http://www.850500.com/news/70169.html
转载请保留,谢谢!
查看更多相关内容>>php,购物车完整实现代码
相关文章
  • php,购物车完整实现代码

    PHP功能实现:PHP购物车的构思PHP功能实现:PHP购物车的构思网站开发万变不离其宗-离不开“增删改查”,购物车也一样,今日本人就不揣浅陋,谈谈自己对购物车的一些浅薄看法。一个...

推荐范文