|
|
|
ผมจะทำให้มันเพิ่มค่าเดิม จากการคลิ๊กที่รายการสินค้าที่มีอยู่ในลิสต์วิวอยู่แล้ว ได้อย่างไรครับ |
|
|
|
|
|
|
|
คือตอนนี้เวลาผมกดรายการสินค้าที่เคยเลือกซื้อมาแล้ว มันจะลิสต์กันเป็นแถวๆลงไปในรายการเลยครับ คือผมต้องการให้มันอัพเดทจากสินค้าที่เคยสั่งซื้อไปแล้ว ต้องทำอย่างไรบ้างครับ รบกวนทีครับ ขอบคุณครับ
Code (PHP)
<?
session_start();
if (!isset($_SESSION['CART'])){ $_SESSION['CART'] = array(); }
if (isset($_POST['txtname']) && isset($_POST['txtpricex']) && isset($_POST['txtUnit']) && isset($_POST['txtimage'])){
$ITEM = array(
'id' => $_POST['mo_id'],
'name' => $_POST['txtname'],
'priceper' => $_POST['txtpricex'],
'unit' => $_POST['txtUnit'] ,
'image' => $_POST['txtimage']
);
$_SESSION['CART'][] = $ITEM;
header('Location: ' . $_SERVER['PHP_SELF']);
}
else if (isset($_GET['remove'])){
unset($_SESSION['CART'][$_GET['remove']]);
header('Location: ' . $_SERVER['PHP_SELF']);
}
else if (isset($_GET['empty'])){
session_destroy();
header('Location: ' . $_SERVER['PHP_SELF']);
}
else if (isset($_POST['update'])) {
foreach ($_POST['items_unit'] as $itemID => $unit) {
if ($unit == 0) {
unset($_SESSION['CART'][$itemID]);
}
else if($unit >= 1) {
$_SESSION['CART'][$itemID]['unit'] = $unit;
}
}
header('Location: ' . $_SERVER['PHP_SELF']);
}
?>
<!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=windows-874" />
<script type="text/jscript" src="../js/jquery-1.4.4.js"></script>
<script type="text/javascript" src="../js/highslide-with-gallery.js"></script>
<link rel="stylesheet" type="text/css" href="../js/highslide.css" />
<link rel="stylesheet" type="text/css" href="../css/css.css" />
<title>ตะกร้าสินค้า</title>
<script type="text/javascript">
hs.graphicsDir = '../js/graphics/';
hs.align = 'center';
hs.transitions = ['expand', 'crossfade'];
hs.outlineType = 'rounded-white';
hs.wrapperClassName = 'controls-in-heading';
hs.fadeInOut = true;
//hs.dimmingOpacity = 0.75;
// Add the controlbar
if (hs.addSlideshow) hs.addSlideshow({
//slideshowGroup: 'group1',
interval: 5000,
repeat: false,
useControls: true,
fixedControls: false,
overlayOptions: {
opacity: 1,
position: 'top right',
hideOnMouseOut: false
}
});
</script>
</head>
<body>
<? include('head-menu.php');?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"> </th>
</tr>
</table>
<table width="945" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<th width="8" scope="col"><img src="../image/onebit_line1.png" width="8" height="24" /></th>
<th width="931" scope="col" class="bgline1" align="left"><span class="style1">ตะกร้าสินค้า</span></th>
<th width="10" scope="col" align="left"><img src="../image/onebit_line3.png" width="7" height="24" /></th>
</tr>
<tr>
<th scope="col" class="bgline2"> </th>
<td scope="col" bgcolor="#FFFFFF"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th colspan="3" scope="col" class="dline1"> </th>
</tr>
<tr>
<th width="0%" height="29" class="dline2" scope="col"> </th>
<th width="99%" bgcolor="#eff5ea" scope="col"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="4%" height="35" align="right" scope="col"><img src="../image/accept.png" width="16" height="16" /></th>
<th width="63%" scope="col"> </th>
<th width="33%" scope="col"> </th>
</tr>
</table></th>
<th width="1%" scope="col" class="dline3" bgcolor="#eff5ea"> </th>
</tr>
<tr>
<th colspan="3" scope="col" class="dline4"> </th>
</tr>
</table></th>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td scope="col">
<form method="post" action="" name="shoppingcart" enctype="application/x-www-form-urlencoded">
<? ob_start()?>
<table width="100%" height="30" border="0" cellspacing="0" cellpadding="0" bgcolor="#CCCCCC">
<tr>
<th width="5%" scope="col" class="style1">ลบ</th>
<th width="15%" scope="col" class="style1">รูปสินค้า</th>
<th width="52%" scope="col" class="style1">ชื่อสินค้า</th>
<th width="10%" scope="col" class="style1">ราคาต่อหน่วย</th>
<th width="8%" scope="col" class="style1">จำนวน</th>
<th width="10%" scope="col" class="style1">รวม</th>
</tr>
</table>
<?php
$_SESSION['total'] = 0;
foreach ($_SESSION['CART'] as $itemNumber => $item) {
?>
<table width="100%" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td height="1" colspan="13" valign="bottom" scope="col" class="line1-99"><img src="../image/emp.gif" width="5" height="5" /></td>
</tr>
<tr id="item<?=$itemNumber;?>">
<td width="0%" align="center" height="66" class="line99" scope="col"> </td>
<td width="5%" align="center" scope="col"><a href="?remove=<?=$itemNumber?>"><img src="../image/cart_delete.png" width="16" height="16" border="0" title="ลบ" /></a></td>
<td width="0%" align="center" scope="col" class="line99"> </td>
<td width="15%" align="center" scope="col"><? if($item['image'] == ""){
echo "<img src=../image/no_image.jpg width=107 height=58 border=0 />";
}else{?>
<div class="highslide-gallery">
<a href="../backend/images/<?=$item['image']?>" class="highslide" onclick="return hs.expand(this)">
<img src="../backend/images/<?=$item['image']?>" width="107" height="58" /></a></div>
<? } ?>
</td>
<td width="0%" align="center" scope="col" class="line99"> </td>
<td width="53%" align="left" scope="col" class="style1"> <?=$item['name']?></td>
<td width="0%" align="center" class="line99" scope="col"> </td>
<td width="10%" align="center" scope="col" class="style1"><?=number_format($item['priceper'],2,'.',',')?></th>
<td width="0%" align="center" class="line99" scope="col"> </td>
<td width="8%" align="center" scope="col" class="style1"><input name="items_unit[<?=$itemNumber?>]" type="text" id="item_unit<?=$itemNumber?>" value="<?=$item['unit']?>" size="2" maxlength="5" /></td>
<td width="0%" align="center" class="line99" scope="col"> </td>
<td width="9%" align="center" class="style1" scope="col"><?=number_format($item['unit'] * $item['priceper'],2,'.',',')?></td>
<td width="0%" scope="col" class="line99-2"> </td>
</tr>
<tr>
<td height="5" colspan="13" class="line1-99-2" scope="col"><img src="../image/emp.gif" width="5" height="5" /></td>
</tr>
</table>
<?php
$_SESSION['total'] += $item['unit'] * $item['priceper'];
}
?>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th scope="col"><img src="../image/emp.gif" width="5" height="5" /></th>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th height="22" scope="col"> </th>
<th scope="col"> </th>
<th align="right" scope="col">
<?php $_SESSION['CART_HTML'] = ob_get_flush(); ?>
<input name="update" id="update" type="submit" value="อัพเดท"/>
</th>
</tr>
<tr>
<th width="12%" height="30" bgcolor="#CCCCCC" scope="col"><a href="index.php"><img src="../image/continue.gif" border="0" /></a></th>
<th width="76%" bgcolor="#CCCCCC" scope="col"> </th>
<th width="12%" bgcolor="#CCCCCC" scope="col"><a href="?empty"><img src="../image/delete.gif" border="0" /></a></th>
</tr>
</table>
<table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th width="73%" scope="col"> </th>
<th width="27%" scope="col"> </th>
</tr>
<tr>
<th scope="col"> </th>
<td scope="col"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<th colspan="3" class="red-line1" scope="col"> </th>
</tr>
<tr>
<th width="2%" class="red-line3" scope="col"> </th>
<td width="96%" scope="col"><table width="100%" border="0" cellspacing="0" cellpadding="0">
<tr>
<td width="55%" height="20" align="right" class="style1" scope="col">ราคารวม : </td>
<td width="45%" scope="col" class="style1" align="center">฿ <?=number_format($_SESSION['total'],2,'.',','); ?> บาท</th>
</tr>
<tr>
<td align="right" height="20" class="style1" scope="col">ภาษีมูลค่าเพิ่ม : </td>
<td scope="col" align="center" class="style1">฿ <?=number_format(0.07*$_SESSION['total'],2,'.',','); ?> บาท</th>
</tr>
<tr>
<th align="right" height="20" class="style1" scope="col">ราคารวมทั้งหมด : </th>
<th scope="col" align="center" class="style3">฿ <?=number_format((0.07*$_SESSION['total'])+$_SESSION['total'],2,'.',','); ?> บาท</th>
</tr>
<tr>
<th align="right" height="20" class="style1" scope="col"> </th>
<th scope="col" align="center" class="style3"> </th>
</tr>
<tr>
<th height="20" colspan="2" align="center" class="style1" scope="col"><img src="../image/byer.gif" width="150" height="40" /></th>
</tr>
<tr>
<th height="5" colspan="2" align="center" class="style1" scope="col"><img src="../image/emp.gif" width="5" height="5" /></th>
</tr>
</table></td>
<th width="2%" class="red-line4" scope="col"> </th>
</tr>
<tr>
<th colspan="3" class="red-line2" scope="col"> </th>
</tr>
</table></td>
</tr>
<tr>
<th scope="col"> </th>
<th scope="col"> </th>
</tr>
</table>
</form>
</td>
</tr>
</table></td>
<th scope="col" class="bgline3"> </th>
</tr>
<tr>
<th scope="col"><img src="../image/onebit_line6.png" width="8" height="23" /></th>
<th scope="col" class="bgline4"> </th>
<th scope="col" align="left"><img src="../image/onebit_line8.png" width="7" height="23" /></th>
</tr>
</table>
</body>
</html>
Tag : PHP, JavaScript, jQuery, CakePHP
|
|
|
|
|
|
Date :
2011-01-18 09:08:29 |
By :
Dragons_first |
View :
885 |
Reply :
1 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
.................
|
|
|
|
|
Date :
2011-01-18 15:51:27 |
By :
Dragons_first |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|