|
 |
|
รบกวนช่วยดูโค๊ดนี้ให้ทีค่ะ ตอนนี้จะให้มีคำนวนราคาสินค้า แต่มันคำนวนราคาปกติ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?
<?php
session_start();
require_once('../inc/config.inc.php');
function deleteFromCart($cartId = 0)
{
if (!$cartId && isset($_GET['cid']) && (int)$_GET['cid'] > 0) {
$cartId = (int)$_GET['cid'];
}
if ($cartId) {
$sql = "DELETE FROM tbl_cart
WHERE ct_id = $cartId";
$result = mysql_query($sql) or die("deleteFromCart() " . mysql_error());
}
echo "<meta http-equiv='refresh' content='1;url=cart.php' />";
}
function deleteAbandonedCart()
{
$yesterday = date('Y-m-d H:i:s', mktime(0,0,0, date('m'), date('d') - 1, date('Y')));
$sql = "DELETE FROM tbl_cart
WHERE ct_date < '$yesterday'";
$result = mysql_query($sql) or die("deleteFromCart() " . mysql_error());
}
$action=$_GET[action];
//echo "$action<hr>";
switch ($action) {
case "add" :
//echo "Hello ,$action<hr>";
$productId = $_GET[book_id];
//echo "$productId<hr>";
$sql2 = "SELECT id,book_name,price,picture FROM books WHERE id = '$productId'";
$result2 = mysql_query($sql2) or die("xyz " . mysql_error());
$rs2=mysql_fetch_row($result2);
$pd_name=$rs2[1];
$ct_price=$rs2[2];
$photo_prd=$rs2[3];
//echo "$productId,$pd_name,$ct_price,$photo_prd<hr>";
$_SESSION[sid] = session_id();
//$sid = session_id();
$sql = "SELECT pd_id FROM tbl_cart WHERE pd_id = '$productId' AND ct_session_id = '$_SESSION[sid]'";
$result = mysql_query($sql) or die("xyz2 " . mysql_error());
$cartNm=mysql_num_rows($result);
if ($cartNm == 0) {
//echo $_SESSION[sid];
$sql = "INSERT INTO tbl_cart (pd_id,pd_name, ct_qty,ct_price, ct_session_id, ct_date,pd_img)
VALUES ('$productId','$pd_name', '1','$ct_price', '$_SESSION[sid]', NOW(),'$photo_prd')";
$result = mysql_query($sql) or die("xyz3 " . mysql_error());
} else {
$sql = "UPDATE tbl_cart
SET ct_qty = ct_qty + 1
WHERE ct_session_id = '$_SESSION[sid]' AND pd_id = $productId";
$result = mysql_query($sql) or die("xyz400 " . mysql_error());
}
deleteAbandonedCart();
echo "<meta http-equiv='refresh' content='0;url=cart.php' />";
break;
case "update" :
$cartId = $_POST['hidCartId'];
$productId = $_POST['hidProductId'];
$itemQty = $_POST['txtQty'];
$numItem = count($itemQty);
$numDeleted = 0;
$notice = '';
for ($i = 0; $i < $numItem; $i++) {
$newQty = (int)$itemQty[$i];
if ($newQty < 1) {
deleteFromCart($cartId[$i]);
$numDeleted += 1;
}
$sql = "UPDATE tbl_cart
SET ct_qty = $newQty
WHERE ct_id = {$cartId[$i]}";
$result = mysql_query($sql) or die("UPDATE tbl_cart " . mysql_error());
}
echo "<meta http-equiv='refresh' content='0;url=cart.php' />";
break;
case "delete" :
if (!$cartId && isset($_GET['cid']) && (int)$_GET['cid'] > 0) {
$cartId = (int)$_GET['cid'];
}
if ($cartId) {
$sql = "DELETE FROM tbl_cart
WHERE ct_id = $cartId";
$result = mysql_query($sql) or die("deleteFromCart() " . mysql_error());
}
echo "<meta http-equiv='refresh' content='0;url=cart.php' />";
break;
}
?>
?>
//ตอนนี้โค๊ดคำนวนราคาสินค้าปกติได้ค่ะ แต่อยากให้มันคำนวณราคา ลดด้วย ถ้าหากมีสินค้าราคาลดอ่ะค่ะ ต้อง ใส่ตรงไหนค่ะ
Tag : - - - -

|
|
 |
 |
 |
 |
Date :
2010-05-02 01:15:39 |
By :
กะทิ |
View :
1177 |
Reply :
2 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ไม่ทราบว่าตอนเขียนงาน ได้วางโครงสร้างตรงจุดนี้ไว้ด้วยเปล่าค่ะ
ในส่วนการลดสินค้านะค่ะ คือเราไม่เห็นฐานข้อมูล มันก็บอกยากนะค่ะ ถ้าไงส่งฐานข้อมูลมาให้ดูได้ไหมค่ะ
สอบถามเพิ่มเติมทางเมล์ก็ได้ค่ะ เผื่อเราไม่ได้เข้ามาในเว็บ จะได้บอกได้ถูกนะค่ะ
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็แทรกเข้าไปตรงโค๊ดคำนวนราคาสินค้านั่นแหละค่ะ ไม่รู้ว่าคุณคำนวณยังไงเนาะ
อธิบายง่าย ๆ คือ เอาราคา - ส่วนลด ก่อนแล้วค่อยเอาไปรวมกับราคารวมน่ะค่ะ
|
 |
 |
 |
 |
Date :
2010-05-05 15:32:20 |
By :
ultrasiam |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 04
|