Register Register Member Login Member Login Member Login Forgot Password ??
PHP , ASP , ASP.NET, VB.NET, C#, Java , jQuery , Android , iOS , Windows Phone
 

Registered : 109,027

HOME > PHP > PHP Forum > ช่วยหน่อยคับ echo $cartOutput; ใน cart.php ละไม่มีอะไรออมาเลย ดูหลายรอบก็ถูกหมดละ



 

ช่วยหน่อยคับ echo $cartOutput; ใน cart.php ละไม่มีอะไรออมาเลย ดูหลายรอบก็ถูกหมดละ

 



Topic : 100176

Guest




ช่วยหน่อยคับ echo $cartOutput; ละไม่มีอะไรออมาเลย

-----------------------------------------------------------cart.php-----------------------------------------------------------------------
Code (PHP)
<?php 
session_start(); // Start session first thing in script
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php 
if (isset($_POST['pid'])){
	$pid = $_POST['pid'];
	$wasFound = false;
	$i = 0;
	//if the cart session variable is not set or cart arraty is empty
if (!isset($_SESSION["cart_array"])||count($_SESSION["cart_array"]) < 1){
	//RUN IF THE CART IS EMPTY OR NOT SET
	$_SESSION["cart_array"] = array(1 => array("item id" => $pid, "quantity" => 1));
} else {
	// RUN IF THE CART HAS AT LEAST ONE ITEM IN IT
	foreach ($_SESSION["cart_array"] as $each_item){
		$i++;
		while (list($key, $value) = each($each_item)){
			if ($key == "item_id" && $value == $pid){
				// That item is in cart already so lets adjust its quantity using array_splice()
				array_splice($_SESSION["cart_array"], $i-1, 1, array(array("item_id" => $pid, "quantity" => $each_item['quantity'] + 1)));
				$wasFound = true;
			}// close if condition
	 	 }// close while loop
	  }// close foreach loop
	  if ($wasFound == false){
		  array_push($_SESSION["cart_array"], array("item_id" => $pid, "quantity" => 1));
	  }
  }
}
?>
<?php 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 2 (if user chooses to empty their shopping cart
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
if (isset($_GET['cmd']) && $_GET['cmd'] == "emptycart"){
	unset($_SESSION["cart_array"]);
}
?>
<?php 
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//       Section 3 (render the cart for the user to view)
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
$cartOutput = "";
if (!isset($_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1){
	$cartOutput = "<h2 align='center'>Your shopping cart is empty</h2>";
} else {
	$i = 0;
	foreach ($_SESSION["cart_array"] as $each_item){
		$i++;
		$cartOutput .= "<h2>Cart item $i</h2>";
		while (list($key, $value) = each($each_item)){
			$cartOutput .= "$key: $value<br />";
		}
	}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
</head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title>Untitled Document</title>
<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	left:0px;
	top:1px;
	width:800px;
	height:336px;
	z-index:1;
}
#apDiv2 {
	position:absolute;
	left:1px;
	top:339px;
	width:254px;
	height:468px;
	z-index:2;
}
#apDiv3 {
	position:absolute;
	left:1px;
	top:14px;
	width:794px;
	height:19px;
	z-index:3;
}
#apDiv4 {
	position:absolute;
	left:258px;
	top:338px;
	width:763px;
	height:471px;
	z-index:4;
}
-->
</style>
</head>

<body>
<div id="apDiv4">
  <table width="100%" border="1">
      <tr>
	      <td valign="top"> <p>&nbsp;</p>
	  <p>
	  <?php echo $cartOutput;?>
    <p><br />
      <a href="cart.php?cmd=emptycart">Click Here to Empty Your Shopping Cart</a><p></td>
        </tr>
    </table>
</div>
<dd>
<div id="apDiv1"><img src="../images/Head.jpg" width="1024" height="338" /></div>
<div id="apDiv2"><img src="../images/login_02.jpg" width="255" height="468" /></div>
</body>
</html>


--------------------------------------------------------------------product.php----------------------------------------------------------------------------
Code (PHP)
<?php 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors', '1');
?>
<?php 
if (isset($_GET['id'])) {
	include "storescript/connect_to_mysql.php";
	$id = preg_replace('#[^0-9]#i', '', $_GET['id']); 
	// Use this var to check to see if this ID exists, if yes then get the product 
	// details, if no then exit this script and give message why
	$sql = mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1");
	$productCount = mysql_num_rows($sql); // count the output amount
    if ($productCount > 0) {
		// get all the product details
		while($row = mysql_fetch_array($sql)){ 
			 $product_name = $row["product_name"];
			 $price = $row["price"];
			 $details = $row["details"];
			 $category = $row["category"];
			 $subcategory = $row["subcategory"];
			 $date_added = strftime("%b %d, %Y", strtotime($row["date_added"]));
         
		 }
		 
	} else {
		echo "That item does not exist.";
	    exit();
	}
		
} else {
	echo "Data to render this page is missing.";
	exit();
}
mysql_close();
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-874" />
<title><?php echo $product_name; ?></title>
<style type="text/css">
<!--
#apDiv1 {
	position:absolute;
	left:0px;
	top:1px;
	width:800px;
	height:336px;
	z-index:1;
}
#apDiv2 {
	position:absolute;
	left:1px;
	top:339px;
	width:254px;
	height:468px;
	z-index:2;
}
#apDiv3 {
	position:absolute;
	left:1px;
	top:14px;
	width:794px;
	height:19px;
	z-index:3;
}
#apDiv4 {
	position:absolute;
	left:258px;
	top:338px;
	width:763px;
	height:290px;
	z-index:4;
}
-->
</style>
</head>

<body>
<div id="apDiv4">
	  <table width="100%" border="6">
	    <tr>
	      <td width="21%" align="center" valign="top"><p><br />
	        &nbsp;<img src="inventory_images/<?php echo $id; ?>.jpg" alt="<?php echo $product_name; ?>" width="136" height="165" border="1" />
            </p>
	      &nbsp; <a href="inventory_images/<?php echo $id; ?>">View Full Size Image</a></td>
	      <td width="79%" valign="top"><h3>&nbsp;<?php echo $product_name; ?></h3>
	        <p> &nbsp;<?php echo $price; ?>&nbsp;B.</p>
	        <p> &nbsp;<?php echo "$subcategory $category"; ?></p>
	        <p> &nbsp;<?php echo $details; ?></p>
	        <p>
           	<form id="form1" name="form1" method=""post action="cart.php">
            	<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>"  />
            	<input type="submit"  name="button" id="button" value="Add to Shopping Cart"  />
            </form>
          </td>
        </tr>
      </table>
	  <p><br />
  </p>
</div>
<dd>
<div id="apDiv1"><img src="../images/Head.jpg" width="1024" height="338" /></div>
<div id="apDiv2"><img src="../images/login_02.jpg" width="255" height="468" /></div>
</body>
</html>




Tag : PHP, HTML/CSS, JavaScript, Web Service







Move To Hilight (Stock) 
Send To Friend.Bookmark.
Date : 2013-09-08 10:08:30 By : golf View : 700 Reply : 4
 

 

No. 1



โพสกระทู้ ( 1,569 )
บทความ ( 2 )



สถานะออฟไลน์
Twitter Facebook Blogger

ลอง var_dump($_SESSION["cart_array"]); ดูหน่อยครับว่ามันมีอัลไลบ้าง






แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-08 12:26:08 By : itpcc
 


 

No. 2



โพสกระทู้ ( 74,058 )
บทความ ( 838 )

สมาชิกที่ใส่เสื้อไทยครีเอท

สถานะออฟไลน์
Twitter Facebook

Code เยอะน่ะครับ ลองดูระบบที่ผมเขียนเป็นตัวอย่าง ง่าย ๆ สั้น ๆ

PHP สร้างระบบตะกร้าสั่งซื้อสินค้า Shopping Cart ด้วย Session และ Array

แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-09 06:27:58 By : mr.win
 

 

No. 3

Guest


ตอบความคิดเห็นที่ : 2 เขียนโดย : mr.win เมื่อวันที่ 2013-09-09 06:27:58
รายละเอียดของการตอบ ::
คือถ้าแก้ ต้องแก้ เยอะเลย อะคับ ยังไงช่วยดูหน่อยได้ ไหม คับ admin


แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-09 14:18:43 By : golf
 


 

No. 4

Guest


Code (PHP)
  	<form id="form1" name="form1" method=""post action="cart.php">
            	<input type="hidden" name="pid" id="pid" value="<?php echo $id; ?>"  />
            	<input type="submit"  name="button" id="button" value="Add to Shopping Cart"  />
            </form>


เจอ แล้วคับที่ผิด เส้นผมบังภูเขา 55555
แสดงความคิดเห็นโดยอ้างถึง ความคิดเห็นนี้
Date : 2013-09-09 15:55:22 By : golf
 

   

ค้นหาข้อมูล


   
 

แสดงความคิดเห็น
Re : ช่วยหน่อยคับ echo $cartOutput; ใน cart.php ละไม่มีอะไรออมาเลย ดูหลายรอบก็ถูกหมดละ
 
 
รายละเอียด
 
ตัวหนา ตัวเอียง ตัวขีดเส้นใต้ ตัวมีขีดกลาง| ตัวเรืองแสง ตัวมีเงา ตัวอักษรวิ่ง| จัดย่อหน้าอิสระ จัดย่อหน้าชิดซ้าย จัดย่อหน้ากึ่งกลาง จัดย่อหน้าชิดขวา| เส้นขวาง| ขนาดตัวอักษร แบบตัวอักษร
ใส่แฟลช ใส่รูป ใส่ไฮเปอร์ลิ้งค์ ใส่อีเมล์ ใส่ลิ้งค์ FTP| ใส่แถวของตาราง ใส่คอลัมน์ตาราง| ตัวยก ตัวห้อย ตัวพิมพ์ดีด| ใส่โค้ด ใส่การอ้างถึงคำพูด| ใส่ลีสต์
smiley for :lol: smiley for :ken: smiley for :D smiley for :) smiley for ;) smiley for :eek: smiley for :geek: smiley for :roll: smiley for :erm: smiley for :cool: smiley for :blank: smiley for :idea: smiley for :ehh: smiley for :aargh: smiley for :evil:
Insert PHP Code
Insert ASP Code
Insert VB.NET Code Insert C#.NET Code Insert JavaScript Code Insert C#.NET Code
Insert Java Code
Insert Android Code
Insert Objective-C Code
Insert XML Code
Insert SQL Code
Insert Code
เพื่อความเรียบร้อยของข้อความ ควรจัดรูปแบบให้พอดีกับขนาดของหน้าจอ เพื่อง่ายต่อการอ่านและสบายตา และตรวจสอบภาษาไทยให้ถูกต้อง

อัพโหลดแทรกรูปภาพ

Notice

เพื่อความปลอดภัยของเว็บบอร์ด ไม่อนุญาติให้แทรก แท็ก [img]....[/img] โดยการอัพโหลดไฟล์รูปจากที่อื่น เช่นเว็บไซต์ ฟรีอัพโหลดต่าง ๆ
อัพโหลดแทรกรูปภาพ ให้ใช้บริการอัพโหลดไฟล์ของไทยครีเอท และตัดรูปภาพให้พอดีกับสกรีน เพื่อความโหลดเร็วและไฟล์ไม่ถูกลบทิ้ง

   
  เพื่อความปลอดภัยและการตรวจสอบ กระทู้ที่แทรกไฟล์อัพโหลดไฟล์จากที่อื่น อาจจะถูกลบทิ้ง
 
โดย
อีเมล์
บวกค่าให้ถูก
<= ตัวเลขฮินดูอารบิก เช่น 123 (หรือล็อกอินเข้าระบบสมาชิกเพื่อไม่ต้องกรอก)







Exchange: นำเข้าสินค้าจากจีน, Taobao, เฟอร์นิเจอร์, ของพรีเมี่ยม, ร่ม, ปากกา, power bank, แฟลชไดร์ฟ, กระบอกน้ำ

Load balance : Server 04
ThaiCreate.Com Logo
© www.ThaiCreate.Com. 2003-2024 All Rights Reserved.
ไทยครีเอทบริการ จัดทำดูแลแก้ไข Web Application ทุกรูปแบบ (PHP, .Net Application, VB.Net, C#)
[Conditions Privacy Statement] ติดต่อโฆษณา 081-987-6107 อัตราราคา คลิกที่นี่