View Single Post
Old 11-28-2012, 12:30 PM   PM User | #9
tonygot
New Coder

 
Join Date: Nov 2012
Posts: 14
Thanks: 3
Thanked 0 Times in 0 Posts
tonygot is an unknown quantity at this point
It doesn't matter where I add it to the script, it will always show up zero and the total does not show like the other pages. I tried also making the product page a unique include.php and that also does not work. You can see about 7 lines down on the product page I added the "count.php". It works like a charm on all the other pages, but only the product page it resets, or does not acknowledge it is there. I believe it has something to with the "if ($productCount > 0) {" but if I tamper with that, it will not display properly.

I am so close I can taste it! I just can't get past this part! Here is a link to the site again to see the live version if interested.


PRODUCT PAGE SCRIPT
PHP Code:
<?php 
ob_start
();
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors''1');
?>
<?php 
include("php/count.php");?>
<?php 
// Check to see the URL variable is set and that it exists in the database
if (isset($_GET['id'])) {
    
// Connect to the MySQL database  
include_once"store/storescripts/connect_to_mysql.php";
    
$id preg_replace('#[^0-9]#i'''$_GET['id']); 
    
// Use this var to check to see if this ID exists, if yes then get the product 
    // details, if no then exit this script and give message why
    
$sql mysql_query("SELECT * FROM products WHERE id='$id' LIMIT 1");
    
$productCount mysql_num_rows($sql); // count the output amount
    
if ($productCount 0) {
        
// get all the product details
        
while($row mysql_fetch_array($sql)){ 
             
$product_name $row["product_name"];
             
$partnumber $row["partnumber"];
             
$subpartnumber $row["subpartnumber"];
             
$yearavail $row["yearavail"];
             
$category $row["category"];
             
$subcategory $row["subcategory"];
             
$details $row["details"];
             
$grams $row["grams"];
             
$sealed $row["sealed"];
             
$price $row["price"];
             
$date_added strftime("%b %d, %Y"strtotime($row["date_added"]));
         }
    } else {
        echo 
"That item does not exist.";
        exit();
    }
} else {
    echo 
"Data to render this page is missing.";
    exit();
}
mysql_close();
ob_end_flush();
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />

<title><?php echo $category?> - <?php echo $subcategory?> - <?php echo $product_name?></title>
<link rel="stylesheet" type="text/css" href="content.css"/>
<link rel="stylesheet" type="text/css" href="main.css"/>
<link  rel="stylesheet" type="text/css" href="style.css">
<meta name="viewport" content="width=1200, height=800, initial-scale=1" />

          
</head>
<body>
<!-- Start Page Container -->
<div class="pagecontainer">                   
<?php include('php/header.php'); ?>                    
<?php include('php/navagation.php'); ?>                  
<div class="wrapcontent"> <!-- Start wrapcontent--> 
<?php include('php/l_contain.php'); ?>      <!-- Left Container -->                                                
<!-- Start CENTER container-->     
<div class="centercontainer">

<!-- INSERT CENTER CONTAINER DYNAMIC INFORMATION BELOW HERE ONLY. DO NOT CHANGE ANYTHING ABOVE. -->  

<div class="productWrap">                                    <!-- Start Product WRAP-->
<div class="productTitleLarge"><?php echo $category?> - <?php echo $subcategory?> - <?php echo $product_name?></div>


<div class="pictureContent"><!-- Start Picture CONTENT WRAP -->
<div class="productPicture"><!-- Start Picture -->
<img src="../store/inventory_images/<?php echo $id?>.jpg" width="253" height="311" alt="<?php echo $product_name?>"/> </div><!-- END Product Picture-->
<div class="productPictureEnlarge"><!-- Start Picture Enlarge--></div><!-- END Picture Enlarge-->
</div><!-- END Picture CONTENT WRAP -->

<div class="productInfoWrap"><!-- Start Product Information WRAP -->
<div class="productInfo"><!-- Start Product Information-->
<div class="productHeader"></div>
<div class="productPrice">$<?php echo $price?></div>
<div class="productQuantity"></div>
<div class="productAddtoCartLarge">
<form id="form1" name="form1" method="post" action="cart.php">
<input type="hidden" name="pid" id="pid" value="<?php echo $id?>"/>
<input type="image" src="images/addtocartup.jpg" id="button" alt="Add to Shopping Cart"/>
</form>

</div>
<div class="productGap"></div>
<div class="productInfoTitle">Product Information</div>
<div class="productYearReleased">Year Released: <?php echo $yearavail?></div>
<div class="productPartNumber">Part Number: #<?php echo $partnumber?></div>
<div class="productSubPartNumber">Item Number: <?php echo $subpartnumber?></div>
<div class="productCategory">Category: <?php echo $category?></div>
<div class="productSubCategory">Sub-Category: <?php echo $subcategory?></div>
<div class="productWeight">Weight in grams: <?php echo $grams?>(g)</div>
</div><!-- END Product Information-->
</div><!-- END Product Information WRAP -->

<div class="productDetails">Product Details</div>
<div class="productDetailsInfo"> <?php echo $details?></div>

<div class="productButtons"> <!-- Start Product Buttons-->

  
</div><!-- END Product Buttons-->


</div>                                                        <!-- END Product WRAP-->




<!-- THIS ENDS INSERT CENTER CONTAINER DYNAMIC INFORMATION ABOVE HERE ONLY. DO NOT CHANGE ANYTHING BELOW.-->     
</div>  <!-- End CENTER container-->
<?php include('php/r_container.php'); ?>    <!-- Right Container -->       
<?php include('php/footer.php'); ?> 
</div><!-- End wrapcontent-->
</div><!-- End pagecontainer-->
</body>
</html>

COUNT PAGE (Include) SCRIPT
PHP Code:
<?php 
ob_start
(); 
// Script Error Reporting
error_reporting(E_ALL);
ini_set('display_errors''1');
include_once
"store/storescripts/connect_to_mysql.php";
$show ""$display ""$count2""
$cartOutput "";
$cartTotal "";
$cartWeight "";
$cartQty "";
if (!isset(
$_SESSION["cart_array"]) || count($_SESSION["cart_array"]) < 1) {
$cartOutput "<h3>Your shopping cart is currently empty!</h3>";
} else {
$i 0
    foreach (
$_SESSION["cart_array"] as $each_item) { 

$item_id$each_item['item_id'];
    
$sql mysql_query("SELECT * FROM products WHERE id='$item_id' LIMIT 1");
    while (
$row mysql_fetch_array($sql)) {
    
$product_name $row["product_name"];
    
$price $row["price"];
    
$subpartnumber $row["subpartnumber"];
    
$grams $row["grams"];
    
}
$pricetotal$price $each_item['quantity'];
$weighttotal$grams $each_item['quantity'];
$cartWeight$weighttotal $cartWeight;
$cartQty$each_item['quantity'] + $cartQty;
$cartTotal $pricetotal $cartTotal;

setlocale(LC_MONETARY"en_US");
$pricetotal money_format("%10.2n",$pricetotal);

//Dynamic table row assembly
$cartOutput .= "<tr>";
$cartOutput .= "<td style=\"color:#206691;\" align=\"center\">".$product_name'<br/><img src="../store/inventory_images/' $item_id '.jpg" width="58" height="59" </td>';  
$cartOutput .= "<td style=\"color:#666;\" align=\"center\">".$subpartnumber."</td>";
$cartOutput .= '<td style=\"color:#666;\" align=\"center\"><form action="cart.php" method="post">
<input name="quantity" type="text" value="'
.$each_item['quantity'].'" size="1" maxlength="1" />
<input name="adjustBtn' 
$item_id '" type="submit" value="Change" />
<input name="quantity_to_adjust" type="hidden" value="' 
$item_id '" /></form></td>';  
//$cartOutput .= "<td style=\"color:#666;\" align=\"center\">".$each_item['quantity']."</td>";  
$cartOutput .= "<td style=\"color:#666;\" align=\"center\">".$weighttotal."(g)</td>";  
$cartOutput .= "<td style=\"color:#666;\" align=\"center\">$".$price."</td>";  
$cartOutput .= "<td style=\"color:#d87921; \" align=\"center\">".$pricetotal."</td>";  
$cartOutput .= '<td style=\"color:#666;\" align=\"center\"><form action="cart.php" method="post"><input name="deleteBtn' $item_id '" type="submit" value="X" /><input name="index_to_remove" type="hidden" value="' .$i'" /></form></td>';  
$cartOutput .= '</tr>'
    
$i++;    
    
$loop $i ;// New code to test the zero function ENDS here.
$count $each_item['quantity'];
//session_register('final');  
 
if ($loop == )
 {
 
$_SESSION['final'] = $count
 }
 else if (
$loop )
 {
 
$display $_SESSION['final'];
 
$count2 $display;
 
$display $count2 $count;
 
$_SESSION['final'] = $display;
 }
 
$show $_SESSION['final'];
    }
    
setlocale(LC_MONETARY"en_US");
    
$cartTotal money_format("%10.2n",$cartTotal);
    
$cartTotal="".$cartTotal." USD";
}
ob_end_flush();
?>
Thanks again for your help so far!!!

Last edited by tonygot; 11-28-2012 at 01:30 PM..
tonygot is offline   Reply With Quote