Thank you Jade for replying to my post. As to your question, the total price of all the items is calculated after the for loop that displays each item. Here is the entire loop in PHP form. The calculation total is on the bottom.
There was no problem before I added a shipping calculation chunk of code and $_SESSION values in the loop.
Code: Select all
<td> Your cart contains
<?= $num_items ?>
item(s)<br /><br />
<a href="#" onClick="history.go(-1)"><img src="images/topbuttons/shopping.gif" alt="Continue Shopping" /></a>
<?PHP
$total=0;
for($i=0;$i<sizeof($_SESSION['cart']);$i++){
$val=$_SESSION['cart'][$i];
$items= split("\|\|",$val);
if($items[0]!=""){
$query = "SELECT *,category from products,categories where categories.id=products.pid and products.id=" . $items[0];
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$line = mysql_fetch_array($result, MYSQL_ASSOC);
//if (isset($line)){
mysql_free_result($result);
?>
<!-- I am unable to add a thumbnail to the product because the $_POST id for the thumbnails of each individual item is the same as the category's thumbnail, which means I have to edit the database in order to change that and I (nor CrystalTech I suspect) know how to alter a MYSQL database to that extent. -->
<br />
<hr />
<span class="style1">
<!-- <img src="<?PHP //echo $line['thumbnail']?>" alt="product" /><br /> -->
<?= stripslashes($line['category']).":";?>
</span>
<?= stripslashes($line['name']) ?>
<? if($line['dims']!=''){ ?>
<br />
<span class="style1">Dimensions:</span>
<?=
stripslashes (substr(($line['dims']), 0, 70))?>
<?
//if shipping weight is present then extract details
$itemshippinginfo = array();
$dims = $line['dims'];
//if shipcost present extract it
$shipcostKV = strstr($dims,'shipcost=');
$shipcost = substr($shipcostKV,9); // returns all but the keyword=
$n = strpos($shipcost,' ');
//$shipcost = substr($shipcost,0,$n); // convert shipping cost to session
if ($shipcost!=''){
$c++."<br />";
echo "<br /><span class='style1'>Shipping Cost:</span> $" .$shipcost;
$_SESSION['shipcost'][$c]=$shipcost;
//echo "<br />".$_SESSION['shipcost'][$c];
}
if (!strstr($dims,'shipdims='))
{
echo "<br /> Shipping dimensions not yet provided.";
}
else
{
//echo "<br /> g is".
$g++."<br />";
$j=NULL;
$itemdims = substr($line['dims'],strpos($line['dims'],'shipdims'.$j)+strlen('shipdims'.$j)+1,strpos($line['dims'],'shipweight'.$j)-strpos($line['dims'],'shipdims'.$j)-strlen('shipweight'.$j));
if(strpos($line['dims'],"shipdims".($j+2)))
{
$itemweight = substr($line['dims'],strpos($line['dims'],'shipweight'.$j)+strlen('shipweight'.$j)+1,strpos($line['dims'],' ',strpos($line['dims'],'shipweight'.$j))-(strpos($line['dims'],'shipweight'.$j)+strlen('shipweight'.$j))-1);
}
else
{
//extract shipping dimensions and weight
$itemweight = substr($line['dims'],strpos($line['dims'],'shipweight'.$j)+strlen('shipweight'.$j)+1);
}
$itemshippinginfo[0]['length'] = substr($itemdims,0,strpos(strtolower($itemdims),'x'));
$itemshippinginfo[0]['width'] = substr($itemdims,strpos(strtolower($itemdims),'x')+1,strpos(strtolower($itemdims),'x',strpos(strtolower($itemdims),'x')+1)-strpos(strtolower($itemdims),'x')-1);
$itemshippinginfo[0]['height'] = substr($itemdims,strpos(strtolower($itemdims),'x',strpos(strtolower($itemdims),'x')+1)+1);
$itemshippinginfo[0]['weight'] = $itemweight;
$j=2;
while(strpos($line['dims'],"shipdims".$j))
{
$itemdims = substr($line['dims'],strpos($line['dims'],'shipdims'.$j)+strlen('shipdims'.$j)+1,strpos($line['dims'],'shipweight'.$j)-strpos($line['dims'],'shipdims'.$j)-strlen('shipweight'.$j));
if(strpos($line['dims'],"shipdims".($j+1)))
{
$itemweight = substr($line['dims'],strpos($line['dims'],'shipweight'.$j)+strlen('shipweight'.$j)+1,strpos($line['dims'],' ',strpos($line['dims'],'shipweight'.$j))-(strpos($line['dims'],'shipweight'.$j)+strlen('shipweight'.$j))-1);
}
else
{
$itemweight = substr($line['dims'],strpos($line['dims'],'shipweight'.$j)+strlen('shipweight'.$j)+1);
}
$itemshippinginfo[$j]['length'] = substr($itemdims,0,strpos(strtolower($itemdims),'x'));
$itemshippinginfo[$j]['width'] = substr($itemdims,strpos(strtolower($itemdims),'x')+1,strpos(strtolower($itemdims),'x',strpos(strtolower($itemdims),'x')+1)-strpos(strtolower($itemdims),'x')-1);
$itemshippinginfo[$j]['height'] = substr($itemdims,strpos(strtolower($itemdims),'x',strpos(strtolower($itemdims),'x')+1)+1);
$itemshippinginfo[$j]['weight'] = $itemweight;
$j++;
}
if(is_numeric($itemshippinginfo[0]['length'])) {
echo "<br /><span class='style1'>Shipping Dimensions: </span>".$itemshippinginfo[0]['length']."" Long, ".$itemshippinginfo[0]['width']."" Wide, ".$itemshippinginfo[0]['height']."" High. Weight of package, ".$itemshippinginfo[0]['weight']." pounds.";
if($itemshippinginfo[2]['length']!=''){
echo "<br /><span class='style1'>Shipping Dimensions of Second Box: </span>".$itemshippinginfo[2]['length']."" Long, ".$itemshippinginfo[2]['width']."" Wide, ".$itemshippinginfo[2]['height']."" High. Weight of package, ".$itemshippinginfo[2]['weight']." pounds.";
}
;}
//echo "<br /><br />";
//$numbcheck = substr($itemdims, 0, 1);
/*if(is_numeric($numbcheck)){
echo $itemdims."<br /><br />";
var_export($itemshippinginfo);}
else{echo $shipcost;}
*/
//echo $i;
//echo $j."<br />";
if (is_numeric(substr($itemshippinginfo[0]['length'],0,1)));{
$_SESSION['shiplength'][$g]=$itemshippinginfo[0]['length'];
$_SESSION['shipwidth'][$g]=$itemshippinginfo[0]['width'];
$_SESSION['shipheight'][$g]=$itemshippinginfo[0]['height'];
$_SESSION['shipweight'][$g]=$itemshippinginfo[0]['weight'];
if (strlen($itemshippinginfo[2]['length'])>0) {
$g++;
$_SESSION['shiplength'][$g]=$itemshippinginfo[2]['length'];
$_SESSION['shipwidth'][$g]=$itemshippinginfo[2]['width'];
$_SESSION['shipheight'][$g]=$itemshippinginfo[2]['height'];
$_SESSION['shipweight'][$g]=$itemshippinginfo[2]['weight'];
}
}
}
}
?>
<br />
<span class="style1">Glass Color:</span>
<?= stripslashes($items[1]) ?>
<?}?>
<? if($items[2]!=''){ ?>
<br />
<span class="style1">Finish:</span>
<?= stripslashes($items[2]) ?>
<?}?>
<? if($items[3]!=''){ ?>
<br />
<span class="style1">Stocks:</span>
<?= stripslashes($items[3]) ?>
<?}?>
<? if($items[4]!=''){ ?>
<br />
<span class="style1">Cord Color:</span>
<?= stripslashes($items[4]) ?>
<?}?>
<? if($items[5]!=''){
$ceiling= split("\|",stripslashes($items[5]));
?>
<br />
<span class="style1">Ceiling Height:</span>
<?= $ceiling[0] ?>
'
<?}?>
<? if($items[6]!=''){
?>
<br />
<span class="style1">Glass Shape:</span>
<?= $items[6] ?>
<?}?>
<? if($items[7]!=''){
?>
<br />
<span class="style1">Leaf Option:</span>
<?= $items[7] ?>
<?}?>
<? if($items[8]!=''){ ?>
<br />
<span class="style1">Ceiling Cap:</span>
<?= stripslashes($items[8]) ?>
<?}?>
<br />
<span class="style1">Price:</span> $
<?
if($line['ceiling']=='Y' && $line['static']=='N'){
$query = "SELECT * from ceiling where deleted=0 and pid=" . $items[0];
$result = mysql_query($query) or die("Query failed : " . mysql_error());
$ceil_cost = mysql_fetch_array($result, MYSQL_ASSOC);
$line['price']=$ceil_cost['h' . $ceiling[0]];
mysql_free_result($result);
}
echo number_format($line['price'],2);
?>
Select one of the following options to modify this item<br />
<br />
<? echo '<a class="sub" href="viewcart5.php?back=' . urlencode($_GET['back']) . '&action=rem&id=' . $i . '"><img src="https://www.jezebelgallery.com/images/topbuttons/removefromcart.gif" alt="Remove" /></a> '; ?><br />
<?
$total+=$line['price'];
}
//}
?>
<td> <a href="<?= $_GET['back']?>"><img src="images/topbuttons/shopping.gif" alt="Continue Shopping" /></a><br /></td>
</tr>
<tr>
<td align="right" class="style1"><br />
Cart subtotal:<br />
$
<?= number_format($total,2)?>
USD</td>