|
|
|
ช่วยผมเอาข้อมูลลงฐานข้อมูลหน่อยคับ จ้างก็ได้คับผมจะ present วันอาทิตย์นี้คับติดแค่เอาลงฐานข้อมูลอย่างเดียวคับ |
|
|
|
|
|
|
|
จ้างก็ได้คับผมจะ present วันอาทิตย์นี้คับติดแค่เอาลงฐานข้อมูลอย่างเดียวคับ
โค้ด
<?php
error_reporting(E_ALL);
session_start();
include("include/connectionDB.php");
$expire = 3600;
$time=time();
$expire=$time+$expire;
$script_url=$_SERVER["PHP_SELF"];
if(!isset($_SESSION['cart']))
{
if(isset($_COOKIE['cart']))
{
$_SESSION['cart']=array();
$_SESSION['cart']=unserialize(stripslashes($_COOKIE['cart']));
$_SESSION['total_items']=cart_calculate_items($_SESSION['cart']);
$_SESSION['total_price']=cart_calculate_price($_SESSION['cart']);
}
else
{
$_SESSION['cart']=array();
$_SESSION['total_items']=0;
$_SESSION['total_price']=0.00;
$s_cart = serialize($_SESSION['cart']);
setcookie('cart',$s_cart,$expire);
}
}
if($_GET['action']=='add')
{
$item=$_GET['pid'];
if(isset($_SESSION['cart'][$item]))
{
$_SESSION['cart'][$item]++;
}
else
{
$_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']);
header("Location:$script_url?action=view");
exit;
}
if($_GET['action']=="del")
{
$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;
}
if($_REQUEST['action']=='updat')
{
$item=$_REQUEST['pid'];
$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;
}
if($_GET['action']=="view")
{
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 price from product where pro_id ='$productID'";
$result = mysql_query($query);
if($result)
{
$row_result=mysql_fetch_assoc($result);
$item_price=$row_result['price'];
$price+=$item_price*$qty;
}
}
}
return $price;
}
//====================================
function db_to_array($result)
{
$result_array=array();
for($count=1;$row=@mysql_fetch_array($result);$count++)
$result_array[$count]=$row;
return $result_array;
}
//====================================
function cart_get_item_details($productID)
{
$query="select * from product where pro_id='$productID'";
$result = mysql_query($query);
$row_result = mysql_fetch_assoc($result);
return $row_result;
}
//===================================
function cart_show($cart,$pictures='false',$editable='true')
{
include("cart_top.php");
$i=1;
foreach($cart as $productID=>$qty)
{
$product = cart_get_item_details($productID);
$bgcolor=($i++%2)?'#F@FAEB':'#E6F2DF';
echo"<form>\n";
echo"<tr bgcolor=\"$bgcolor\">\n";
echo"<td align=\"center\">";
echo"<a href=\"basket.php?action=del&pid=".$product['pro_id']."\">";
echo"ลบ";
echo"</a>";
echo"</td>\n";
echo"<td align=\"center\">".$product['proname']."</td>\n";
echo"<td valign=top align=center>";
echo"<input type=\"text\" name=\"pro_id\" value=$qty size=2>";
echo"</td>\n";
echo"<td valign=top align=right>".number_format($product['price'],
2,'.',',')."</td>\n";
echo"<td valign=top align=right>".number_format(($qty*$product['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>
</td>\n";
echo"<td align=left><b>ยอดรวม</b></td>\n";
echo"<td align=right><font color=red><b>".number_format($_SESSION['total_price'],2,'.',',')."</font></b></td>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td colspan=3rowspan=4> </td>\n";
echo"<td align=left><b>ค่าจัดส่ง</b></td>\n";
echo"<td align=right>";
if($_SESSION['total_price']==0)
{
$pay_delivery=0;
}
else
{
if($_SESSION['total_price']>=3500)
$pay_delivery=0;
else
$pay_delivery=150;
}
echo number_format($pay_delivery,2,'.',',');
echo" บาท</td>\n";
echo"</tr>\n";
echo"<tr>\n";
// echo"<td align=left><b>ภาษี 7%</b></td>\n";
// echo"<td align=right bgcolor=\"#FFFF99\">";
// $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 class=style6 align=left><b>รวมทั้งสิ้น</b></td>\n";
echo"<td align=right bgcolor=\"#FFFFCC\"><b>";
$paymoney =($_SESSION['total_price']+$pay_delivery);
echo number_format($paymoney,2,'.',',');
echo" บาท</b></td>\n";
echo"</tr>\n";
echo"<tr>\n";
echo"<td colspan=5><br>\n";
echo"หากท่านไม่ได้รับสินค้าภายใน 3 วัน โปรดติดต่อกลับ 085-127-5611</td>\n";
echo"</tr>\n";
echo"</table>\n";
echo"<div align=center>\n";
echo"<p align=center>\n";
echo"<table align=center>\n";
echo"<tr width=100%>\n";
echo"<td align=center>\n";
echo"<form action=\"product.php\"><input type=\"submit\" value=\"เลือกซื้อสินค้าต่อ\"></form>\n";
echo"</td>\n";
echo"<td align=center>\n";
echo"<form action=\"payment.php\"><input type=\"submit\" value=\"ชำระเงิน\"></form>\n";
echo"</td>\n";
echo"</tr>\n";
echo"</table>\n";
echo"</div>\n";
include("cart_bottom.php");
}
include("include/closeDB.php");
?>
Tag : - - - -
|
|
|
|
|
|
Date :
27 พ.ค. 2551 11:03:05 |
By :
ออม |
View :
1352 |
Reply :
2 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
insert into ตาราง (ฟิลด์, ฟิลด์,ฟิลด์,ฟิลด์,ฟิลด์,ฟิลด์) Values(ค่า, ค่า, ค่า,ค่า,ค่า,ค่า);
เขียน sql statement ให้ได้รูปตามนั้น
แล้วสั่งให้มันรัน เช่น
$query = "INSERT INTO " .$ชื่อตาราง. "($ชื่อฟิลด์1, $ชื่อฟิลด์2, $ชื่อฟิลด์3)";
$query=. "VALUES('$ข้อมูล1', '$ข้อมูล1', '$ข้อมูล1')";
// ระวังในส่วนของ values ต้องดูชนิดของฟิลด์ด้วย ถ้าเป็น number ไม่ต้องมีเครื่องหมาย single quote ล่ะ
@mysql_query($query);
|
|
|
|
|
Date :
27 พ.ค. 2551 18:44:56 |
By :
แวะมาเจอ |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
ขอบคุณคับ
|
|
|
|
|
Date :
28 พ.ค. 2551 08:36:10 |
By :
ออม |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Load balance : Server 02
|