|
|
|
ขอโค้ดเกี่ยวกับการขายสินค้าหน่อยคับ ตอนนี้กำลังทำโปรเจกค์จบนะคับ เขียน php ใครมีกรุณาช่วยหน่อยนะคับ จะเป็นพระคุณอย่างสูง |
|
|
|
|
|
|
|
อยากได้โคด้ที่มันต่อจากนี้นะคับ
<?php
error_reporting(E_ALL);
session_start(); // ?????????????
include "ConnectionDb.php"; // ??????????????????????
$expire = 3600; // ??????????? $expire ??????????????????
$time = time(); // ??????????? $time ???????????????????
$expire = $time + $expire; // ????????????????????
$script_url = $_SERVER["PHP_SELF"]; // ??????????????????
// ??????? ???????????????????????????????? cart
if(!isset($_SESSION['cart'])) {
// ???????? ??????? ??????????????? cart ?????????????
if(isset($_COOKIE['cart'])) {
// ??????????????????? cart ???????????????????
@$_SESSION['cart'] = array();
// ?????????????????? cart ????????????? unserialize() ???????????
@$_SESSION['cart'] = unserialize(stripslashes($_COOKIE['cart']));
// ??????????????????? total_items ?????????????????????????????? cart_calculate_items()
@$_SESSION['total_items'] = cart_calculate_items($_SESSION['cart']);
// ??????????????????? total_price ?????????????????????????????? cart_calculate_price()
@$_SESSION['total_price'] = cart_calculate_price($_SESSION['cart']);
} else {
// ??????????????????? cart ???????????????????
$_SESSION['cart'] = array();
// ??????????????????? total_items ??? total_price ??????? 0
$_SESSION['total_items'] = 0;
$_SESSION['total_price'] = 0.00;
// ?????????????? s_cart ??????? ???????????????? Bytestream ???????????????? cart
$s_cart = serialize($_SESSION['cart']);
// ?????????????????? cart ??????? ????????? $s_cart
setcookie('cart', $s_cart, $expire);
}
}
// --------------------------------------------------
// ?????????????????
// --------------------------------------------------
// ????????? action ??????????????? URL ??????? add
if( @$_GET['action'] == 'add' ) {
// ????????????? pid ?????????? URL ???????????? $item
$item = $_GET['pid'];
// ???????????????? cart ?????????????????????????????????????????
if(isset($_SESSION['cart'][$item])) {
// ????????? 1
$_SESSION['cart'][$item]++;
} else {
// ????????????? 1
$_SESSION['cart'][$item] = 1;
}
$_SESSION['total_items'] = cart_calculate_items($_SESSION['cart']);
$_SESSION['total_price'] = cart_calculate_price($_SESSION['cart']);
$s_cart = serialize($_SESSION['cart']);
// ??????? Redirect
header("Location: $script_url?action=view");
exit;
}
// --------------------------------------------------
// ??????????????
// --------------------------------------------------
// ????????? action ??????????????? URL ??????? del
if( @$_GET['action'] == "del" ) {
// ????????????? pid ?????????? URL ???????????? $productID
$productID = $_GET['pid'];
unset($_SESSION['cart'][$productID]);
$_SESSION['total_items'] = cart_calculate_items($_SESSION['cart']);
$_SESSION['total_price'] = cart_calculate_price($_SESSION['cart']);
$s_cart = serialize($_SESSION['cart']);
header("Location: $script_url?action=view");
exit;
}
// --------------------------------------------------
// ?????????????????????
// --------------------------------------------------
// ????????? action ??????????????? URL ??????? update
if( @$_REQUEST['action'] == 'update' ) {
// ????????????? pid ?????????? URL ???????????? $item
$item = $_REQUEST['pid'];
// ????????????? quantity ?????????? URL ???????????? $quantity
$quantity = $_REQUEST['quantity'];
if(isset($_SESSION['cart'][$item])) {
$_SESSION['cart'][$item] = $quantity;
}
$_SESSION['total_items'] = cart_calculate_items($_SESSION['cart']);
$_SESSION['total_price'] = cart_calculate_price($_SESSION['cart']);
$s_cart = serialize($_SESSION['cart']);
header("Location: $script_url?action=view");
exit;
}
// --------------------------------------------------
// ??????????????
// --------------------------------------------------
// ????????? action ??????????????? URL ??????? view
if( @$_GET['action'] == "view" ) {
// ???????????????????? cart_show()
cart_show( $_SESSION['cart'], $pictures = 'false', $editable = 'true');
}
// --------------------------------------------------
// ??????????????????????????????????
// --------------------------------------------------
function cart_calculate_items($cart) {
$items = 0;
if(is_array($cart)) {
foreach($_SESSION['cart'] as $productID => $qty) {
$items += $qty;
}
}
return $items;
}
// -------------------------------------------------------------------------------
// ??????????????????????? ?????????????????????????????????
// -------------------------------------------------------------------------------
function cart_calculate_price($cart) {
$price = 0.00;
if(is_array($cart)) {
foreach($cart as $productID => $qty) {
$query = "SELECT pd_price FROM tbl_product WHERE pd_id='$productID'";
$result = mysql_query($query);
if($result) {
$row_result = mysql_fetch_assoc($result);
$item_price = $row_result['pd_price'];
$price += $item_price*$qty;
}
}
}
return $price;
}
// ------------------------------------------------------------------
// ???????????????????????? ???????????
// ------------------------------------------------------------------
function qty_combo($qty_n, $pname) {
echo " <select onChange=\"Update_qty('parent',this,0)\">\n";
for ( $i=1; $i<=20; $i++ ) {
if ( $i == $qty_n ) {
echo "\t\t<option value=\"?action=update&pid=". $pname ."&quantity=$i\" selected>$i</option>\n";
} else {
echo "\t\t<option value=\"?action=update&pid=". $pname ."&quantity=$i\">$i</option>\n";
}
}
echo " </select>\n";
}
// ---------------------------------------------------------------------------------
// ???????????????? tbl_product ?????????????????????????
// ---------------------------------------------------------------------------------
function cart_get_item_details($productID) {
$query = "SELECT * FROM tbl_product WHERE pd_id='$productID'";
$result = mysql_query($query);
$row_result = mysql_fetch_assoc($result);
return $row_result;
}
// ---------------------------------------------------------------------------------
// ?????????????????????????? ? ???????? ?????????????????????? ?
// ---------------------------------------------------------------------------------
function cart_show($cart, $pictures = 'false', $editable = 'true') {
include "template_cart_top.php";
$i = 1;
foreach($cart as $productID => $qty) {
$product = cart_get_item_details($productID);
$bgcolor = ($i++ % 2) ? '#F2FAEB' : '#E6F2DF';
echo "<form>\n";
echo "<tr class=\"style2\" bgcolor=\"$bgcolor\"> \n";
echo "<td align=\"center\">";
echo "<a href=\"basket.php?action=del&pid=". $product['pd_id'] ."\">";
echo "<img src=\"images/icon_remove.gif\" alt=\"ÃÇÁ '" . $product['pd_name'] . "'\" border=\"0\">";
echo "</a>";
echo "</td> \n";
echo "<td valign=\"top\">" . $product['pd_name'] . "</td> \n";
echo "<td valign=top align=center>";
echo qty_combo($qty, $product['pd_id']);
echo "</td> \n";
echo "<td valign=top align=right>" . number_format($product['pd_price'], 2, '.', ',') . "</td> \n";
echo "<td valign=top align=right>". number_format(($qty*$product['pd_price']), 2, '.', ',') ."</td> \n";
echo "</tr> \n";
echo "</form>\n";
}
echo " <tr> \n";
echo " <td colspan=5><hr size=1></td> \n";
echo " </tr> \n";
echo " <tr> \n";
echo " <td colspan=3 align=\"center\" valign=middle> ¤Ô´¤èÒ¢¹Êè§ 50 ºÒ·</td> \n";
echo " <td align=left class=\"style2\"><b>ÃÇÁ</b></td> \n";
echo " <td align=right class=\"style2\">". number_format($_SESSION['total_price'], 2, '.', ',') ."</td> \n";
echo " </tr> \n";
echo " <tr> \n";
echo " <td colspan=3 rowspan=4> </td> \n";
echo " <td align=left class=\"style2\"><b>¤èÒ¢¹Êè§</b></td> \n";
echo " <td align=right class=\"style2\">";
if ( $_SESSION['total_price'] == 0 ) {
$pay_delivery = 0;
} else {
if ( $_SESSION['total_price'] >= 500 )
$pay_delivery = 0;
else
$pay_delivery = 50;
}
echo number_format($pay_delivery, 2, '.', ',');
echo "</td> \n";
echo " </tr> \n";
echo " <tr> \n";
echo " <td align=left class=\"style2\"><b>ÀÒÉÕ 7%</b></td> \n";
echo " <td align=right bgcolor=\"#FFFF99\" class=\"style2\">";
$tax = $_SESSION['total_price']*0.07;
echo number_format($tax, 2, '.', ',');
echo "</td> \n";
echo " </tr> \n";
echo " <tr> \n";
echo " <td colspan=3> <hr size=1> </td> \n";
echo " </tr> \n";
echo " <tr> \n";
echo " <td align=left class=\"style1\"><span class=\"style2\"><b>ÃÇÁÊØ·¸Ô</b></span></td> \n";
echo " <td align=right bgcolor=\"#99FF99\">";
$paymoney = ($_SESSION['total_price']+$pay_delivery+$tax );
echo number_format($paymoney, 2, '.', ',');
echo "</td> \n";
echo " </tr> \n";
echo " <tr> \n";
echo " <td colspan=5><br> \n";
echo " <span class=\"comment style2\">ËÒ¡äÁèä´éÃѺÊÔ¹¤éÒÀÒÂã¹ 3 Çѹ â·ÃµÔ´µèÍ 089-999-9999 </span></td> \n";
echo " </tr> \n";
echo " </table> \n";
echo " <div align=center> \n";
echo " <p align=center>\n";
echo " <a href=\"index.php\"><img src=\"images/icon_con_shopping.gif\" alt=\"àÅ×Í¡ÊÔ¹¤éÒµèÍ\" border=\"0\"></a> \n";
echo " <a href=\"checkout.php\"><img src=\"images/icon_payment.gif\" alt=\"ªÓÃÐà§Ô¹\" border=\"0\"> </a> \n";
echo " </div> \n";
}
include "CloseDb.php";
?>
|
|
|
|
|
Date :
24 ต.ค. 2549 04:32:12 |
By :
ngohtitle |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 05
|