Jump to content

grand total amount....


arunpatal

Recommended Posts

Hi,

 

i need to add total amount and echo it in page.

variable $total_price show total amount of 1 product

but i want to show grand total amount in page.....

 

Please help with this

 

<?php do { ?>

<?php

$total_price = $row_view_order['quantity'] * $row_view_order['price'];

if (isset($row_view_order['productid'])) {
echo '<tr>
 <td id="admin_list_first">'.$row_view_order['product_name'].'</td>
 <td id="admin_list">'.$row_view_order['quantity'].'</td>
 <td id="admin_list">'.$row_view_order['price'].'</td>
<td id="admin_list">'.$total_price.'</td>

</tr>'; }

 else {
	 echo '<tr>
 <td align="left" style="padding-left:10px;"><h3>Please Select Order from order list.</h3></td>
 <td></td>
 <td></td>
<td></td>
</tr>'; }
 ?>



<?php } while ($row_view_order = mysql_fetch_assoc($view_order)); ?>

Edited by arunpatal
Link to comment
Share on other sites

Try this:

 


<?php

$grand_total = 0;

do {

$total_price = $row_view_order['quantity'] * $row_view_order['price'];

$grand_total += $total_price;

if (isset($row_view_order['productid'])) {
echo '<tr>
<td id="admin_list_first">'.$row_view_order['product_name'].'</td>
<td id="admin_list">'.$row_view_order['quantity'].'</td>
<td id="admin_list">'.$row_view_order['price'].'</td>
<td id="admin_list">'.$total_price.'</td>

</tr>'; }

else {
echo '<tr>
<td align="left" style="padding-left:10px;"><h3>Please Select Order from order list.</h3></td>
<td></td>
<td></td>
<td></td>
</tr>'; }
?>



<?php } while ($row_view_order = mysql_fetch_assoc($view_order));

echo 'Grand total: ' . $grand_total;

?>

 

Have a $grand_total variable and increase it with each product's total price (for every iteration of the loop, i.e. for every product) and then display the value of the variable when the loop terminates.

Edited by Andy123
Link to comment
Share on other sites

Try this:

 


<?php

$grand_total = 0;

do {

$total_price = $row_view_order['quantity'] * $row_view_order['price'];

$grand_total += $total_price;

if (isset($row_view_order['productid'])) {
echo '<tr>
<td id="admin_list_first">'.$row_view_order['product_name'].'</td>
<td id="admin_list">'.$row_view_order['quantity'].'</td>
<td id="admin_list">'.$row_view_order['price'].'</td>
<td id="admin_list">'.$total_price.'</td>

</tr>'; }

else {
echo '<tr>
<td align="left" style="padding-left:10px;"><h3>Please Select Order from order list.</h3></td>
<td></td>
<td></td>
<td></td>
</tr>'; }
?>



<?php } while ($row_view_order = mysql_fetch_assoc($view_order));

echo 'Grand total: ' . $grand_total;

?>

 

Have a $grand_total variable and increase it with each product's total price (for every iteration of the loop, i.e. for every product) and then display the value of the variable when the loop terminates.

 

 

Thanks Andy :)

it works

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.