以前我们的购物车都是点击打开网页,都是web 2.0形式的,本文章提供这款php教程 ajax拖动购物车源码,可以拖动商品放在购物车里面,这样更好的适合用户习惯了。
*/
//download by http://www.111cn.net
/* database config */
$db_host = 'localhost';
$db_user = 'root';
$db_pass = 'dcfan2006';
$db_database = 'test';
$link = mysql教程_connect($db_host,$db_user,$db_pass) or die('unable to establish a db connection');
mysql_select_db($db_database,$link);
mysql_query("set names utf8");
?>
tips.
if(!$_post['img']) die("there is no such product!");
$img=mysql_real_escape_string(end(explode('/',$_post['img'])));
$row=mysql_fetch_assoc(mysql_query("select * from internet_shop where img='".$img."'"));
if(!$row) die("there is no such product!");
echo ''.$row['name'].'
'.$row['description'].'
price: $'.$row['price'].'
drag it to your shopping cart to purchase it';
?>
addtocard.php加入购物车
define('include_check',1);
require "../connect.php";
if(!$_post['img']) die("there is no such product!");
$img=mysql_real_escape_string(end(explode('/',$_post['img'])));
$row=mysql_fetch_assoc(mysql_query("select * from internet_shop where img='".$img."'"));
echo '{status:1,id:'.$row['id'].',price:'.$row['price'].',txt:'
'.$row['name'].' | $'.$row['price'].' | remove |
?>
查看购物车页面
your order
$cnt = array();
$products = array();
foreach($_post as $key=>$value)
{
$key=(int)str_replace('_cnt','',$key);
$products[]=$key;
$cnt[$key]=$value;
}
$result = mysql_query("select * from internet_shop where id in(".join($products,',').")");
if(!mysql_num_rows($result))
{
echo '
there was an error with your order!
';}
else
{
echo '
you ordered:
';while($row=mysql_fetch_assoc($result))
{
echo '
'.$cnt[$row['id']].' x '.$row['name'].'
';$total+=$cnt[$row['id']]*$row['price'];
}
echo '
total: $'.$total.'
';}
?>
源码下载地址。
http://down.111cn.net/down/code/php/qitayuanma/2010/1102/21586.html