|
 |
|
ช่วยอธิบายโค๊ดเซสชั่นในระบบตระกร้าสินค้าครับผมทุกบรรทัดเลยนะครับ ไม่เข้าใจเลย ขอบคุณครับ |
|
 |
|
|
 |
 |
|
หน้า basket.php
action="basket_cal.php"
<?
for ($i=0;$i<count($sess_id);$i++){
$pro="select * from tb_product where id_prd='$sess_id[$i]' and amount != 0";
$pro_qu=mysql_query($pro);
$numrows=mysql_num_rows($pro_qu);
if($numrows==0){
$sess_num[$i]=0;
array_splice($sess_id,$i,1);
array_splice($sess_name,$i,1);
array_splice($sess_price,$i,1);
array_splice($sess_num,$i,1);
echo "<script language='JavaScript'>";
echo "alert('สินค้าชิ้นนี้หมดแล้ว กรุณาเลือกสินค้าใหม่');";
echo "</script>";
}else{
$arr=mysql_fetch_array($pro_qu);
if($sess_num[$i]>$arr[amount]){
$sess_num[$i]=$arr[amount];
echo "<script language='JavaScript'>";
echo "alert('สินค้าชิ้นนี้เหลือ $arr[amount] ระบบจะทำการปรับจำนวนสินค้าโดยอัตโนมัติ');";
echo "</script>";
}
}}
หน้าbastket_cal.php
<?
session_start();
if (count($prd_del)==0){
$prd_del=array();
}
for ($i=0;$i<count($sess_id);$i++){
if (!in_array($sess_id[$i],$prd_del)) {
$temp_id[]=$sess_id[$i];
$temp_name[]=$sess_name[$i];
$temp_price[]=$sess_price[$i];
$temp_num[]=$prd_num[$i];
}
}
$sess_id=$temp_id;
$sess_name=$temp_name;
$sess_price=$temp_price;
$sess_num=$temp_num;
if($calculate){
header("location: basket.php");
} else if ($complete){
if($user1==""){
echo "<script language='JavaScript'>";
echo "alert('¤Ø³ÂѧäÁèä´éÊÁѤÃÊÁÒªÔ¡ ¡ÃسÒÊÁѤÃÊÁÒªÔ¡¡è͹');";
echo "</script>";
echo "<meta http-equiv=refresh content=0;URL=register.php>";
}else{
header("location: prd_order.php");
}
}
?>
หน้า bastket_add.php
<?
session_start();
$id_prd=$_GET[id_prd];
session_register("sess_id");
session_register("sess_name");
session_register("sess_price");
session_register("sess_num");
if(count($sess_id)=="0"){
$check=1;
} else if (!in_array($id_prd,$sess_id)) {
$check=1;
}
if ($check==1){
include "connect.php";
$sql="select * from tb_product where id_prd='$id_prd'";
$result=mysql_db_query($dbname,$sql);
$rs=mysql_fetch_array($result);
$sess_id[]=$rs[id_prd];
$sess_name[]=$rs[name_prd];
$sess_price[]=$rs[price_prd];
$sess_num[]=1;
}
header("location:basket.php");
?>
Tag : PHP, MySQL

|
|
 |
 |
 |
 |
Date :
2010-12-20 17:57:28 |
By :
007 |
View :
849 |
Reply :
1 |
|
 |
 |
 |
 |
|
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
หลัก ๆเป็นการนำสินค้าลงใน session น่ะครับ 
|
 |
 |
 |
 |
Date :
2010-12-21 22:59:43 |
By :
webmaster |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 00
|