variable scope prob

A

Anonymous

Guest
Hi guys,

I am trying to calculate total item in one of my while loop but it seems like i couldn't get the shipping value output no matter what qty i insert...

A part of my code:
Code:
<?
while($row = mysql_fetch_array($result)) {
$totalCost += ($row["qty"] * $row["itemPrice"]);
$totalitem += $row["qty"];

?>

<tr>
<td width = "12%" height="25">

<font face="Arial" size="2" color="black"><? echo $row["qty"]; ?>
</font>
</td>

<font face="Arial" size="2" color="black"><? echo number_format($row["itemPrice"], 2,".", "."); ?>
</font>
</td>

<?
} 
// close for while loop
?>

<?
		include "../shipping.php"; // consist all the shipping charges value
		
		if($totalitem == "1")
		{
		$totalCost = ($totalCost + $shipping);
		echo "$shipping";
		}
		else 
		{
		echo "You have ordered more than 1 item. <a href=\"shipping.htm\" target = \"blank\">click here</a> to view the shipping charges information."; 
		} 
		
		?>
		</font>
</td>
            <td width="180"><font face="Arial" size="2" color="black"><b>Total: USD<? echo number_format($totalCost, 2, ".","."); ?>

can u guys give me an idea y this occured ?? is it due to variable scope or what ??

for ur guys info, the totalCost works fine, but the shipping or totalitem isn't working fine...

p.s: the output is blank in the shipping fee column..

please advise...
 
I think you could make it in your query!
Code:
SELECT (qty * itemPrice) AS totalCost FROM table ORDER by table_id
And than use mysql_affected_rows() for the totalitems. Or even using the mysql COUNT() in your query!
 
Back
Top