  | 
		 		   | 
	  	    
          
            
			
	
			
			 
                รบกวนช่วยดูโค๊ดแล้วให้คำแนะนำหน่อยนะค่ะ แก้มาหลายวันแล้ว ไม่เข้าใจอะค่ะ คิดว่ามันน่าจะผิดตรง SESSION 
 
หน้า 1.php แล้ว action ไปที่หน้า cart.php คือ ไปที่หน้า cart แล้ว color กับ propic_id มันทำยังไงถึงจะเรียกใช้ได้ที่ หน้า cart.php ค่ะ 
 
Code 
<select name="proColor" class="txtbox"> 
                                <option value="">Select color</option> 
                                <? 
//===========  Select color from table products_pictures 
$sql_group = "select * from products_pictures WHERE pro_id='".$_GET["pro_id"]."' order by propic_id asc"; 
$dbquery_group = mysql_query($sql_group); 
//$num_rows_group = mysql_num_rows($dbquery_group); 
while ($result = mysql_fetch_array($dbquery_group)) 
{ 
			?> 
			<option value="<?=$result["propic_id"];?>"><?=$result["color"];?></option> 
			<? 
			} 
			?> 
		  </select>  
 
 
โค๊ดหน้า cart.php 
 
Code (PHP) 
if($_GET["pro_id"] != "")
{
	for($i=0;$i<=count($_SESSION["strpro_id"]);$i++)
	{
			if($_SESSION["strpro_id"][$i] == $_GET["pro_id"])
			{
			header("location:$_SERVER[PHP_SELF]");
			exit();
			}
	}
}
//============If user add product this will store these information to Session
if(trim($_GET["pro_id"])!= "")
{
	$_SESSION["strP"]=$_SESSION["strP"]+1;
	$_SESSION["strpro_id"][$_SESSION[strP]]=$_GET["pro_id"];
	$_SESSION["strQuanlity"][$_SESSION[strP]]=1;
	session_write_close();
	header("location:$_SERVER[PHP_SELF]");
}	
//============ If have delete item of purchase
if(trim($_GET["action"]) == "Del")
{
	$_SESSION["strpro_id"][$_GET[P]]="";
	$_SESSION["strQuanlity"][$_GET[P]]="";
	session_write_close();
	header("location:$_SERVER[PHP_SELF]");
}	
//============ If have update purchase item
if(trim($_POST["action"]) == "Update")
{
for($i=0;$i<count($_POST["txtQua"]);$i++)
{	
	$strP=$_POST[txtP][$i];
	$strQ=$_POST["txtQua"][$i];
	if($strQ <= 0)
	{
	$strQ=1;
	}
	$_SESSION["strQuanlity"][$strP]=$strQ;
/*
	$result=select("product","where 1=1 and ProductID='".$_SESSION["strProductID"][$strP]."'");
	if($result["Stock"] < $strQ)
	{
	$_SESSION["strQuanlity"][$strP]=$result["Stock"];
									echo"<script language='JavaScript'>";
									echo"alert('Item # [ $result[ProductCode] ] out of Stock');";
									echo"</script>";	
	}
*/	
	
}	
	session_write_close();
	//============ Jump Refresh one more time
	header("location:$_SERVER[PHP_SELF]");
}	
?>			</td>
      </tr>
      <tr>
        <td><table width="100%" border="1" cellpadding="0" cellspacing="0" bordercolor="#f2f2f6" bgcolor="#FFFFFF">
          <tr>
            <td width="17%" valign="top"><?php require_once('menuleft.php'); ?></td>
            <td valign="top"><table width="99%" border="0" align="center" cellpadding="0" cellspacing="0">
              <tr>
                <td align="center"><img src="images/step1.jpg" width="742" height="57" /></td>
              </tr>
              <tr>
                <td height="46" align="center"><span class="style17">Your cart. </span></td>
              </tr>
              <tr>
                
              </tr>
              <tr>
                <td><table width="99%" border="0" cellspacing="0" cellpadding="0">
                  <tr>
                    <td align="right">  <form action="" method="post" name="frmCart" id="frmCart">
					
                      <span class="style18"><strong>
                      </strong></span>
                      <strong>
                      <input name="action" type="hidden" id="action" value="Update" />
                      </strong>
                      <table width="93%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#333333">
                        <tr>
                          <td width="4%" height="33" align="center" bgcolor="#FFFFFF"><span class="style31">No</span></td>
                          <td width="57%" align="center" bgcolor="#FFFFFF"><span class="style31">Detail</span></td>
                          <td width="12%" align="center" bgcolor="#FFFFFF"><span class="style31">Price</span></td>
                          <td width="18%" align="center" bgcolor="#FFFFFF"><span class="style31">Qauntity</span></td>
                          <td width="9%" align="center" bgcolor="#FFFFFF"><span class="style31">Total</span></td>
                        </tr>
                      </table>
                      <table width="93%" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#333333">
                        <tr>
                           <?
//============ Show how many item user had select
$strNum=0;
$strTotal=0;
for($i=0;$i<=count($_SESSION["strpro_id"]);$i++)
{
//============ select information from product table
$result=select("products where 1=1 and pro_id='".$_SESSION["strpro_id"]["$i"]."'");
$result2=select("products_pictures where 1=1 and pro_id='".$_SESSION["strpro_id"]["$i"]."'");
//$result=select("products.pro_id,products.pro_name,products.pro_code,products_pictures.pro_id,products_pictures.propic_name from products inner join products_pictures on products.pro_id = products_pictures.pro_id where 1=1 and pro_id='".$_SESSION["strpro_id"]["$i"]."' ");
if($result)
{
$strNum++;
?><td width="5%" height="42" align="center" bgcolor="#FFFFFF"><span class="style26">
                             <?=$strNum;?>
                             <br />                            
                             <a href="javascript:if(confirm('Do you want to remove this item')==true){window.location='<?=$_SERVER['PHP_SELF'];?>?action=Del&P=<?=$i;?>';}"><img src="images/deleteC.gif" width="12" height="11" border="0" /></a>
                             </div>
                           </span></td>
                          <td width="5%" height="42" align="left" valign="middle" bgcolor="#FFFFFF"><a href="#"><span class="style32"><img src="products/<?=$result2["propic_name"];?>" width="36" height="29" border="0" /></span><br />
                          </a></td>
                          <td width="49%" align="left" bgcolor="#FFFFFF"><a href="products.php?progroup_id=<?=$result["progroup_id"];?>"><span class="style32"> (
                                <?=$result["pro_code"];?>
) </span> <span class="style26">
<?=$result["pro_name"];?>
<span class="style32">(
<?=$result2["color"];?>
)</span></span></a></td>
                          <td width="12%" height="42" align="right" bgcolor="#FFFFFF"><span class="style26"><?=$result["price"];?>
                          </span></td>
                          <td width="15%" height="42" align="right" bgcolor="#FFFFFF"><span class="style26">
                            <input name="txtP[]" type="hidden" id="txtP[]" value="<?=$i;?>" />
                            <input name="txtQua[]" type="text" id="txtQua<?=$strNum;?>" style="width:30px;text-align:right" value="<?=$_SESSION["strQuanlity"]["$i"];?>" maxlength="3" onchange="checknum(this.value,'txtQua<?=$strNum;?>');" />
							 <? /*if ($_SESSION["strQuanlity"]["i"]<$result2["stock"]) {
							 echo "<script>";
							 echo "alert('This product(".$result["pro_name"].")are sold');";
        					 echo "</script>";
							     }
								 */
								 
							?>
                            <a href="javascript:if(confirm('Do you want to remove this item')==true){window.location='<?=$_SERVER['PHP_SELF'];?>?action=Del&P=<?=$i;?>';}"><br />
                            </a></span></td>
                          <td width="3%" align="right" bgcolor="#FFFFFF"><span class="style26">/<?=$result["unitcall"];?>
                          </span></td>
                          <td width="11%" height="42" align="right" bgcolor="#FFFFFF"><span class="style26"><?="".number_format(($result["price"]+$result["PriceSend"])*$_SESSION["strQuanlity"]["$i"], 2,'.',',');?>
                          </span></td>
                        </tr> <?
								  $strTotal=$strTotal+(($result["price"])*$_SESSION["strQuanlity"]["$i"]);
}
}
?>
                        
                        <tr>
                          <td bgcolor="#FFFFFF"> </td>
                          <td colspan="2" bgcolor="#FFFFFF"><?
							if($strNum==0)
							{
							echo "<br><center><strong><font color=red>YOUR SHOPPING CART IS EMPTY</font></strong></center><br><br>";
							}
							?></td>
                          <td bgcolor="#FFFFFF"> </td>
                          <td colspan="2" bgcolor="#FFFFFF"> </td>
                          <td bgcolor="#FFFFFF"> </td>
                        </tr>
                        <tr>
                          <td colspan="7"></td>
                          </tr>
                      </table>
                      <hr align="center" width="700" color="#f2f2f6" />
                      <br />
                                        <table width="93%" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#333333">
                                          <tr>
                                            <td width="81%" align="right" bgcolor="#FFFFFF"><span class="style26"><strong>Total</strong> (item) in your cart   : </span></td>
                                            <td width="19%" bgcolor="#FFFFFF"><?=$strNum;?></td>
                                          </tr>
                                          <tr>
                                            <td align="right" bgcolor="#FFFFFF"><span class="style26">Shipping cost   : </span></td>
                                            <td bgcolor="#FFFFFF"> </td>
                                          </tr>
                                          <tr>
                                            <td align="right" bgcolor="#FFFFFF"><span class="style26"><strong>Total : </strong>(US DOLLAR $) </span></td>
                                            <td bgcolor="#FFFFFF"><?="".number_format($strTotal, 2,'.',',');?></td>
                                          </tr>
                                        </table><br />
                                        <table width="93%" border="0" align="center" cellpadding="0" cellspacing="0">
                                          <tr>
                                            <td align="right"><input name="BtnContinute" type="button" class="button" id="BtnContinute2" value="Continue to shopping" onclick="window.location='shopping_index.php';" />
 
<?
								  if($strNum>0)
								  {?>
<input name="BtnCalu" type="submit" class="button" id="BtnCalu" value="Caculate" />
 
<input name="BtnPayment" type="button" class="button" id="BtnPayment" value="Check out" onclick="window.location='pay.php';" />
<?}?></td>
                                          </tr>
                                        </table>
                                        <hr align="center" width="750" color="#f2f2f6" />
                    </form>                    </td>
                  </tr>
                </table></td>
              </tr>
            </table></td>
            </tr>
           <tr> 
                <td colspan="2" valign="top">
                  <?php require_once('down.php'); ?>                </td>
        </table></td>
      </tr>
    </table></td>
  </tr>
</table>
</body>
</html>
 
 
รบกวนคนที่เข้าใจเรื่อง session หรือระบบ ecommerce เข้ามาช่วยอธิบายให้ฟังหน่อยนะค่ะ ถือว่าเป็นวิทยาทานนะค่ะ รบกวนด้วยนะค่ะ
 
 
  Tag : PHP, MySQL               
                        | 
           
          
            | 
			
                             | 
           
          
            
              
                   | 
                   | 
                   | 
               
              
                   | 
                
                    
                      | Date :
                          2012-02-17 08:05:53 | 
                      By :
                          มือใหม่หัดขับ | 
                      View :
                          1169 | 
                      Reply :
                          5 | 
                     
                  | 
                   | 
               
              
                   | 
                   | 
                   | 
               
              | 
           
          
            | 
			 | 
           
         
	    
		             | 
		
			  |