没有让这个头正确工作


not getting this header to work correctly

我仍在为此工作,我一直在尝试添加不同的东西,但它不起作用。当我打开网站的时候,网页上的内容都是乱七八糟的,我也不知道为什么。下面是我的代码:

   <?php
// Get all the categories and
// link them to category.php.
// Define and execute the query:
$q = 'SELECT category_id, category FROM categories ORDER BY category';
$r = mysqli_query($dbc, $q);
// Fetch the results:
while (list($fcid, $fcat) = mysqli_fetch_array($r, MYSQLI_NUM)) {
    // Print as a list item.
    echo "<li><a href='"category.php?cid=$fcid'">$fcat</a></li>'n";
    if($_SERVER['PHP_SELF']!="CART FILE"){
                echo "<h1>Cart Contents</h1>";
                echo "<div class='"p2'">";
                $itemCount = count($_SESSION['cart']);
                foreach($_SESSION['cart'] as X=>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.

当我把x=>x变成$k=>$v时,什么都没有发生。我一点也不明白,计数出现了,但两边都不正常。这是网站http://www.elinkswap.com/snorris/header.html我相信这是一个小的东西,但我仍然是一个新手在这个

好吧,我正在编辑这个也许是为了让你们理解我在这里想做什么:在右侧添加购物车中的商品数量,这就是该代码应该做的事情。

修改如下:

foreach($_SESSION['cart'] as X=>X){
   for($i=0;$i<count(X);$i++){
      $itemCount+=X;
  }
}

:

foreach($_SESSION['cart'] as $key=>$X)
{
   for($i=0;$i<count($X);$i++){
      $itemCount+= $X;
   }
}

您确定您的页面被解释为php脚本吗?解释器要考虑的页面默认扩展名是。php,根据版本可能是。php3 .php5。