2011-10-26 18 views
1

私は数日間この作業を進めています。カートを使って何かをすることは決してありませんでしたので、私はこれを理解しようとしています。ここに私のウェブページがあり、あなたが側に目を向けると、私がそれを行うために必要なことをやっておらず、他のコードも表示しています:http://www.elinkswap.com/snorris/header.html。私が何をしようとしているのは、あなたがheader.htmlページにいて、あなたが言うべきカートの内容を見ているときです。それからあなたはアイテムに行き、あなたは1を望んで更新をクリックすると、カートに1アイテムがあると言うはずです。しかし何らかの理由で私はそれを正しく働かせることはできません。ここで私が働いているコードの少しは次のとおりです。カートの合計金額を追加するには

<?php # Script 5.2 - header.html 

/* 
* This page begins the HTML header for the site. 
* The header also creates the right-hand column. 
* This page calls session_start(). 
*/ 

// Need sessions! 
session_start(); 

// Check for a $page_title value: 
if (!isset($page_title)) $page_title = 'WoW::World of Widgets!'; 
?><!DOCTYPE html 
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd"> 
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> 
<head> 
    <title><?php echo $page_title; ?></title> 
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> 
    <link href="./includes/style.css" rel="stylesheet" type="text/css" /> 
</head> 
<body> 
<div class="all"> 

    <div class="box"> 
     <div class="menu"><a href="#">home</a><a href="#">about</a><a href="#">products</a><a href="#">contact</a></div> 
     <div class="header"><img alt="" style="float:right; " src="./images/www.jpg" width="225" height="95" /> 
     <h1>[<span class="style1">WoW</span>] World of Widgets</h1> 
     <div class="clearfix"></div> 
    </div> 

    <div class="newsbar"> 
     <h1>Browse Widget Categories</h1> 
     <div class="p2"><ul> 
<li><a href="category.php?cid=5">Fuzzy Widgets</a></li> 
<li><a href="category.php?cid=4">Non-widget Widgets</a></li> 
<li><a href="category.php?cid=6">Razor-sharp Widgets</a></li> 
<li><a href="category.php?cid=2">Widgets That Bounce</a></li> 
<li><a href="category.php?cid=3">Widgets That Sit There</a></li> 
<li><a href="category.php?cid=1">Widgets That Wiggle</a></li> 
<?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\"></a></li>\n"; 

    if($_SERVER['PHP_SELF']!="CART FILE"){ 
       echo "<h1>Cart Contents</h1>"; 
       echo "<div class=\"p2\">"; 
       $itemCount=$k; 
       foreach($_SESSION['cart'] as $k=>$v){ 

        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. 

     ?></ul></div> 


     <h1>Specials?</h1> 
     <div class="p2"> 
      <p>Maybe place specials or new items or related items here.</p> 
     </div> 

    </div> 

    <div class="content"> 

私はまだこれらの事のいくつかを学んでいますし、これのいくつかは、単に意味をなさないdoesntのと私はそれが仕事を得る傾けます。あなただけの$itemCount変数をインクリメント配列をループする必要はありませんcount();

を使用することにより、配列オブジェクトをカウントすることができ

答えて

2

を見ていただきありがとうございます。

だけ持っている:

$itemCount = count($myShoppingCart);

0

は、カート上のクエリが空または製品の数である場合のエコーをベースにしてください。 $ k => $ Vで参照している値で製品数に達することがあります。これには、これらの値のそれぞれに1つ以上の値があります。つまり、 の結果+各アイテムが複数回注文された回数。

このような何か:

 $aantal += $value ; 

     if ($value < 1 ) { 
     echo"Cart is empty"; 
     } else { 
     echo'<h3>YOURE CART('. $aantal .')</h3>'; 
     } 
関連する問題