|
 |
|
รบกวนอีกรอบค่ะ...ช่วยอธิบาย Code ให้หน่อยนะคะ ได้โปรด อ่านเท่าไรก็ไม่เข้าใจค่ะ |
|
 |
|
|
 |
 |
|
Code (PHP)
<?
session_start(); //เริ่มใช้ session
$id_product=$_GET[id_product]; // รับค่าแบบ GET เก็บไว้ที่ฝั่งทางซ้าย
$_SESSION['sess_id']=$sess_id; //รับค่าจากตัวแปร $sess_id เก็บไว้ที่ตัวแปรแบบ session ทางฝั่งซ้าย
$_SESSION['sess_name']=$sess_name;
$_SESSION['sess_comp']=$sess_comp;
$_SESSION['sess_type']=$sess_type;
$_SESSION['sess_num']=$sess_num;
if(count($sess_id)==0) { // ใช้ฟังก์ชั่น count ได้กับ array เพื่อจะตรวจว่า array มีค่าเป็น 0 หมายความว่าตัวแปรนี้ไม่มีค่าในตัวมันแต่มันต้องเป็นตัวแปร array นะ
$check=1;
}
else if ( !in_array ($id_product, $sess_id) ) { //เช็คว่าค่าในตัวแปร $id_product อยู่ใน ตัวแปร $sess_id หรือไม่ถ้า ไม่ใช่ ให้ทำบรรทัดล่างกำหนด $check = 1
$check=1;
}
if ($check==1) { // ถ้า $check == 1 จริงทำข้างล่าง
include "connect.php"; //เรียกไฟล์นอก
$sql = "select * from product where id_product = '$id_product' " ; // ค่ำสั่ง query
$result = mysql_db_query($dbname,$sql);
$rs = mysql_fetch_array($result);
$sess_id[] = $rs[id_product]; //เอาค่าที่ query ออกมาเก็บในตัวแปร $sess_id ซึ่งการเติม [] หมายความว่าเป็น array แล้วทำการ add เพิ่มค่าเข้าไป
$sess_name[] = $rs[name_product];
$sess_comp[] = $rs[ref_company];
$sess_type[] = $rs[ref_id_type];
$sess_num [] =1;
}
header ("Location: basket.php" ) ; // ไปหน้าที่กำหนด
?>
ตัวแปร $sess_id หรือตัวอื่นถ้าต้องการเช็คค่าว่ามีค่าอะไรบ้างให้ใช้ฟังก์ชั่น print_r
|
 |
 |
 |
 |
Date :
2010-07-06 14:00:36 |
By :
oxygenyoyo |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
พี่ OxyGenyoyo มาช่วยทุกทีเลย ขอบคุณมากนะคะ น่ารักที่สุดเลย
|
 |
 |
 |
 |
Date :
2010-07-06 14:06:52 |
By :
naked13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
เพิ่มเติมค่ะ คือ ถ้าเราจะทำให้มันส่งค่ามา 2 ค่ามาพร้อมกันอ่ะค่ะ เช่น
ส่ง id_product และ id_color มาอ่ะค่ะ คือให้ User เลือก สินค้า และ เลือก สี ได้อ่ะค่ะ จะต้องเขียน code เพิ่มยังไงเหรอคะ
รบกวนด้วยนะคะ (โปรเจคนี้ติดมา 4 เดือนแล้ว ยังคิดไม่ออกเลย )
|
 |
 |
 |
 |
Date :
2010-07-06 14:15:48 |
By :
naked13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ก็ยังงงอ่ะค่ะ
ไม่เข้าใจว่าเมื่อมีตัวแปร id_color เพิ่มเข้ามา จะเข้าเงื่อนไขการ Check ยังไงอ่ะคะ
Code (PHP)
<?
session_start();
$id_product=$_POST[id_product];
$id_color=$_POST[id_color];
$_SESSION['sess_id']=$sess_id;
$_SESSION['sess_name']=$sess_name;
$_SESSION['sess_id_color']=$sess_id_color;
$_SESSION['sess_name_color']=$sess_name_color;
$_SESSION['sess_num']=$sess_num;
if(count($sess_id and $sess_id_color )==0) {
$check=1;
}
else if ( !in_array ($id_color, $sess_id_color ) ) {
$check=1;
}
if ($check==1) {
include "connect.php";
$sql = "select * from tb_product where id_prd = '$id_product' " ;
$result = mysql_db_query($dbname,$sql);
$rs = mysql_fetch_array($result);
$sess_id[] = $rs[id_prd];
$sess_name[] = $rs[name];
$sql1 = "select * from color where id_color = '$id_color' " ;
$result1 = mysql_db_query($dbname,$sql1);
$rs1 = mysql_fetch_array($result1);
$sess_id_color[] = $rs1[id_color];
$sess_name_color[] = $rs1[name_color];
$sess_num [] =1;
}
header ("Location: page3.php" ) ;
?>
อย่างนี้มันก็ไม่ได้อ่ะค่ะ
|
 |
 |
 |
 |
Date :
2010-07-06 16:28:48 |
By :
naked13 |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
 |
|
|
 |
 |
|
ช่วยอธิบายโค้ดพีระมิดหน่อยค่ะว่าตัวแปร x กับ y มันแตกต่างกันยังไง
และใช้งานยังไง ขอบคุณค่ะ
|
 |
 |
 |
 |
Date :
2010-07-30 14:11:46 |
By :
แพน |
|
 |
 |
 |
 |
|
|
 |
 |
|
 |
 |
|
|
|

|
Load balance : Server 02
|