Jump to content

[SOLVED] Calculate Total Cost


bigrossco

Recommended Posts

Not sure if their is the right place to put this.

I have a php page and on it it has results from a database and I am wanting it to show the total cost (qnt * price) and then I also want it to add all the total prices together to give a total price

how can I do this?

Thanks for your help in advance

Ross
Link to comment
https://forums.phpfreaks.com/topic/33446-solved-calculate-total-cost/
Share on other sites

this is how I have coded it:

[code]    <?php


    $host = "$lang_dbhost";
    $user = "$lang_dbuser";
    $pass = "$lang_dbpass";
    $db = "$lang_dbase";

    // open connection
    $connection = mysql_connect($host, $user, $pass) or die ("Unable to connect!");

    // select database
    mysql_select_db($db) or die ("Unable to select database!");



    $query = "SELECT DATE_FORMAT(date,'%d/%m/%Y'), price1, item1, paid, invo_no, item2, price2, qnt1, qnt2
FROM client_invoices WHERE invo_no = '".$_SESSION["invoice"]."'";

    // execute query
    $result = mysql_query($query) or die ("Error in query: $query. ".mysql_error());



?>

<form action="<?=$_SERVER['PHP_SELF']?>" method="post">
  <?php
if (mysql_num_rows($result) > 0) {

echo"<table border = 0>";
echo"<tr>";
while($row = mysql_fetch_row($result)){
echo"<tr>";

echo"<table border = 1>";
echo"<td><b><center>Qty</b></td><td><b><center>Description</b></td><td><b><center>Unit Price</b></td><td><b><center>TOTAL</b></td>";
echo"<tr>";
echo "<td>".$row[7]."</td>";
echo "<td>".$row[2]."</td>";
echo "<td>".$row[1]."</td>";



echo"</tr>";
echo "<td>".$row[8]."</td>";
echo "<td>".$row[5]."</td>";
echo "<td>".$row[6]."</td>";



  }
  }


?>[/code]


I want $row[7] (quantity) to times by $row[1] (unit price)

Ross

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.