[英]add in how many items are in the cart
I can not get this part to work I have even tried to change the $key
to just $k => $v
and it is not outputting what i need to to do. 我无法让这部分工作,我什至试图将
$key
更改为$k => $v
并且它没有输出我需要做的事情。 Should I be changing this line $itemCount=X;
我应该更改此行
$itemCount=X;
to $itemCount=count()
??? 到
$itemCount=count()
??? At this point in time I have not a clue what else to do and its very fustating. 在这一点上,我还不知道还有什么要做的事情,它非常繁琐。 Thanks for all whos look.
谢谢大家的光临。
I need to add in how many items are in the cart 我需要添加购物车中有多少物品
if($_SERVER['PHP_SELF']!="CART FILE"){
echo "<h1>Cart Contents</h1>";
echo "<div class=\"p2\">";
$itemCount=X;
foreach($_SESSION['cart'] as $key=>$X)
{
for($i=0;$i<count($X);$i++){
$itemCount+= $X;
}
}
echo "<a href=\"cart.php\">You have ".$itemCount." total items in your cart.</a>";
echo "</div>\n";
}
} // End of while loop.
Just use the PHP count() method on your $_SESSION['cart'] variable and remove all the other code like your foreach. 只需在$ _SESSION ['cart']变量上使用PHP count()方法,然后删除所有其他代码,例如您的foreach。 This should be fine:
这应该很好:
if($_SERVER['PHP_SELF']!="CART FILE"){
echo "<h1>Cart Contents</h1>";
echo "<div class=\"p2\">";
echo "<a href=\"cart.php\">You have ".count($_SESSION['cart'])." total items in your cart.</a>";
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.