|
 |
|
เกี่ยวกับการ update และคำนวณราคารวม สินค้าในตะกร้า |
|
 |
|
|
 |
 |
|
อยากทราบว่า sql update ของผมมันต้องยังไง
ผมต้องการเอา id + sumprice แล้ว check ว่าในตะกร้า Shopping_cart2 มี id cookie อยู่หรือไม่ ถ้าเคยหยิบใส่ตะกร้าแล้ว
ให้แสดง แสดงตะกร้าสินค้า แล้ว echo พวกที่จะแสดงออกมา
ผมนึกได้ประมาณนี้แต่ยังไม่รู้ว่าต้องใช้ตัวแปรอะไรบ้าง ผิดตรงไหนขอโทษด้วยนะครับ
DB
ตาราง Product
ProductID,id,ProductName,ProductPrice,ProductDetail,amount,Productimh
ตาราง ProductType
id,ProductType
ตาราง Shopping_Cart
id,SumPrice
ตาราง Shopping_Cart2
id,idshopping,ProductID,amount
code หน้า Shopping_Cart_Code.php
Code (PHP)
<?php
if(isset($_COOKIE['Shopping_Cart']))
{
//echo $_COOKIE['Shopping_Cart'];
}
else
{
$conn=odbc_connect ('ac','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="INSERT INTO Shopping_Cart (SumPrice) VALUES (0)";
$sql="UPDATE Shopping_cart SET SumPrice=มันต้องเป็นอะไรครับ";
$rs=odbc_exec($conn,$sql);
setcookie("Shopping_Cart",'111',time()+3600);
echo "Create cookie";
}
require("Shopping_Cart.php");
odbc_close($conn);
?>
<!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>
<link href="css/global.css" media="screen" rel="stylesheet" type="text/css" />
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
</body>
</html>
Code หน้า Shopping_Cart.php
Code (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>
<link href="css/global.css" media="screen" rel="stylesheet" type="text/css" />
<link href="css/style.css" media="screen" rel="stylesheet" type="text/css" />
</head>
<body>
<div id="wrapper">
<ul id="nav" class="clearfix">
<li><a href="index.html">หน้าแรก</a> </li>
<li><a href="About_us.html">เกี่ยวกับเรา</a> </li>
<li><a href="Contact_us.html">ติดต่อเรา</a> </li>
<li><a href="Payment.html">ชำระเงิน</a> </li>
</ul>
<div id="col_main_cart" class="bucket clearfix">
<table class="cart">
<tbody>
<tr class="title_table">
<td class="cart_item">สินค้า</td>
<td class="cart_name"></td>
<td class="cart_price01">ราคา(฿)</td>
<td class="cart_qty">จำนวน</td>
<td class="cart_total">ราคารวม(฿)</td>
</tr>
<tr class="c0">
<td class="cart_item"><img alt="#" src="images/B1.jpg" /></td>
<td class="cart_name">แหวนเงิน สลักลาย</td>
<td class="cart_price01">999</td>
<td class="cart_qty">
<input id="amount_84"type="text"value="1"name="amount_84" style="width: 48px">
</td>
<td class="cart_total green">
999
<input name="Button1" type="button" value="Delete" />
<br/>
<br/>
<input name="Button2" type="button" value="Update" />
</td>
</tr>
<tr>
<td class="cart_overall" colspan="6">
<span class="gray">ราคารวมทั้งหมด</span>
<span class="overall">999</span>
</td>
</tr>
</tbody>
</table>
<div class="bucket_button">
<form action="index.php" method="post" enctype="multipart/form-data">
<input name="Button3" type="submit" value="Continue Shopping" />
</form>
<br/>
<input name="Button2" type="submit" value="Checkout" />
<?php
$conn=odbc_connect ('ac','','');
if (!$conn)
{exit("Connection Failed: " . $conn);}
$sql="SELECT ProductName,ProductPrice,Productimg FROM Product";
$rs=odbc_exec($conn,$sql);
odbc_close($conn);
?>
</div>
</div>
</div>
<div id="footer">
</div>
</body>
</html>
Tag : PHP, Ms Access

|
|
 |
 |
 |
 |
Date :
2011-01-11 11:04:20 |
By :
thegun |
View :
1316 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ผมคิดว่าคุณน่าจะลองหาตัวอย่างจากหนังสือ หรือจากเว็บไซต์เพื่อมาเปิดดูเป็นตัวอย่างดีกว่าครับ ผมอ่านแล้วงง
|
 |
 |
 |
 |
Date :
2011-01-12 10:45:54 |
By :
create_ninku |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|