【发布时间】:2015-01-12 05:41:04
【问题描述】:
最初我让它工作正常,通过 array_push() 函数传递产品 id,从 addtocart.php 到 Shoppingcart.php 显示项目。但是当我在array_push()函数中添加更多变量时,除了单个产品id$_GET['id'],...在接收这个数组的下一页上,它给了我一个错误。
问题是:
在原始的$sql 查询中,它得到了id,它需要显示来自array_push() 的产品信息并将其显示到Shoppingcart.php,但是当我在push_array() 中添加更多变量/信息时,我得到了一个错误。因为它混淆了$sql 查询,因为WHERE id IN 子句......ID 仍然在那里,现在连同其他信息($_GET['size'] 和$_GET['qty']),我只是不知道如何访问它...
Qty 用于我的 while() 循环。
addtocart.php
array_push($_SESSION['cart'], $_GET['id']); //working MAIN
header('Location:shoppingCart.php');
How 2: array_push($_SESSION['cart'], $_GET['id'], $_GET['size'], $_GET['qty']);
//Not Working
shoppingcart.php
<?php
$whereIn = implode(',', $_SESSION['cart']); //working MAIN
$sql = " SELECT * FROM inventory WHERE id IN ($whereIn) "; ?>
<?php while($row = mysql_fetch_array($result)) { ?>
<td valign="top">
<div id="sc_itemBox">
<p class="sc_itemBox_iTEXT"><strong>SIZE:</strong> “”XL?? <em>(Extra Large??)</em></p>
<div id="sc_itemBox_img"><img src="<?php echo $row['imgThumb'];?>" /></div>
<p class=<p class="sc_itemBox_iTEXT"><strong>STYLE#</strong><?php echo $row['styleNUM']; ?> </p>
</div>
</td>
<?php } ?>
【问题讨论】:
-
如果您需要更多信息来更好地了解这里发生的事情,请告诉我,我尽量做到清楚,以免混淆任何人。
-
单引号是写成
‘而不是'(即$_GET[‘size’])还是只是一个错字? -
好吧,我就是这么想的。
-
是的,我打字很快,只是想弄清楚要点...... :)
-
当你
print_r($_SESSION['cart']);时,你的$_SESSION['cart']是什么样子我很难把我的想法集中在你想要做的事情上,所以看到这个数组可能会对我有所帮助。我想我明白了,我认为你需要让你的$_SESSION['cart']更复杂一点。
标签: php session while-loop shopping-cart array-push