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