没有让这个标题正常工作

时间:2011-10-26 13:48:31

标签: php

我仍在努力解决这个问题,我一直试图添加不同的东西,但它不起作用。当我去网站时,这一面都搞砸了,我不知道为什么。这是我的代码:

   <?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 =&gt; x更改为$ k =&gt; $ v时,没有任何反应。我完全不理解这一点,但是双方都完全失控了。这是网站http://www.elinkswap.com/snorris/header.html我确信它很小但我仍然是新手。

好吧我正在编辑这个可能你们要明白我在这里要做的是: 添加右侧购物车中有多少项,这是该代码所要做的..

2 个答案:

答案 0 :(得分:1)

改变这个:

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;
   }
}

它应该有用。

答案 1 :(得分:0)

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

或许你正在使用我看不到的网址重写。