arunpatal Posted January 6, 2013 Share Posted January 6, 2013 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)); ?> Link to comment https://forums.phpfreaks.com/topic/272742-grand-total-amount/ Share on other sites More sharing options...
Andy123 Posted January 6, 2013 Share Posted January 6, 2013 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. Link to comment https://forums.phpfreaks.com/topic/272742-grand-total-amount/#findComment-1403511 Share on other sites More sharing options...
arunpatal Posted January 6, 2013 Author Share Posted January 6, 2013 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 https://forums.phpfreaks.com/topic/272742-grand-total-amount/#findComment-1403583 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.