|
5精币
请问我要怎么实现加减按钮之后对应的合计总价也能够改变并且更新到数据库,我已经整了两天了没整出来,谢谢
<!doctype html>
<html>
<head>
<meta charset="UTF-8">
<title>index</title>
<link rel="stylesheet" href="../public/css/index.css">
</head>
<body>
<?php
include "../public/header.php";
$sqlcart="SELECT * FROM `cart` WHERE `user_id`='".$_SESSION['username']."'";
$qurcart=mysql_query($sqlcart,$con);
$numcart=mysql_num_rows($qurcart);
if($numcart=='0'){
echo "<script language=javascript>";
echo "alert('您还未添加商品到购物车,请先购物');";
echo "document.location='../index.php'";
echo "</script>";
}else{
?>
<div class="main">
<div class="nav"></div>
<div class="content">
<div class="class">
<div class="title">
<a >首页</a> » 购物车
</div>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.6.1.min.js"></script>
<?php
/*
echo "<script>
$(function(){
$('.add').click(function(){
var t=$(this).parent().find('input[class*=text_box]');
t.val(parseInt(t.val())+1)
})
$('.min').click(function(){
var t=$(this).parent().find('input[class*=text_box]');
if(parseInt(t.val())>1){
t.val(parseInt(t.val())-1)
}
})
})
</script>";
*/
?>
<script>
$(function(){
$(".add").click(function(){
var t=$(this).parent().find('input[class*=text_box]');
t.val(parseInt(t.val())+1)
var tot=$(this).parent().find('input[class*=tot]');
var price=$(this).parent().find('input[class*=tot]');
tot.val(parseInt($(this).find('input[class*=text_box]').val())*parseInt($(this).find('input[class*=price]').text()));
})
$(".min").click(function(){
var t=$(this).parent().find('input[class*=text_box]');
if(parseInt(t.val())>1){
t.val(parseInt(t.val())-1)
}
})
})
</script>
<div class="class_shops">
<fieldset>
<form action='xuanzedizhi.php' method='post'>
<table id='tab' border='1px' cellspacing='0'>
<tr>
<th>商品</th>
<th>单价</th>
<th>数量</th>
<th>合计</th>
<th>删除</th>
<th>选择</th>
</tr>
<?php
$tot=0;
while ($arrcart=mysql_fetch_assoc($qurcart)) {
$tot+=$arrcart['num']*$arrcart['price'];
echo "<tr>";
echo "<td>{$arrcart['sname']}</td>";
echo "<td><input class='price' type='text' value='{$arrcart['price']}' disabled /></td>";
//echo "<td ><span class='price'>{$arrcart['price']}</span></td>";
echo "<td><input class='min' name=' ' type='button' value='-'' /><input class='text_box' name='num' type='text' value='{$arrcart['num']}' disabled /><input class='add' name='' type='button' value='+'' /> </td>";
echo "<td><input class='tot' name='total' type='text' value='{$arrcart['zongjia']}' disabled /></td>";
//echo "<td>{$arrcart['zongjia']}</td>";
echo "<td><a href='opcart.php?action=del&shop_id={$arrcart['shop_id']}'>删除</a></td>";
echo "<input type='hidden' name='shop_id' value='{$arrcart['shop_id']}'/>";
echo "<td><input type='checkbox' name='checkbox' id='checkbox_id1' value='{$arrcart['shop_id']}' /></td>";
echo "</tr>";
}
?>
<tr>
<td>总合计:</td>
<td><?php echo @$tot ?></td>
<td colspan='2'><a href="opcart.php?action=clear">清空购物车</a></td>
<td colspan='2'><a href="../index.php">继续购物</a></td>
</tr>
<tr>
<td colspan='6'>
<input type="submit" value='提交订单' style='color:#f00;font-weight:bold;'>
</td>
</tr>
</table>
</form>
</fieldset>
</div>
</div>
</div>
<?php
include "../public/footer.php";
}
?>
</div>
</body>
</html>
|
最佳答案
查看完整内容
PHP SELECT cha询出表的数量是否存在 如果不存在 就新建一个 否则就 UPDATE
一条金光闪闪的小尾巴
|