bigrossco Posted January 9, 2007 Share Posted January 9, 2007 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 pricehow can I do this?Thanks for your help in advanceRoss Quote Link to comment Share on other sites More sharing options...
taith Posted January 9, 2007 Share Posted January 9, 2007 if you want more, you'll need to say how you got your database set up...[code]$result=mysql_query("SELECT * FROM table");while($row=mysql_fetch_array($result)){ $total=$total+$row[cost];}[/code] Quote Link to comment Share on other sites More sharing options...
bigrossco Posted January 9, 2007 Author Share Posted January 9, 2007 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, qnt2FROM 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"> <?phpif (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 Quote Link to comment Share on other sites More sharing options...
bigrossco Posted January 9, 2007 Author Share Posted January 9, 2007 got it working, thanks Quote Link to comment Share on other sites More sharing options...
bigrossco Posted January 9, 2007 Author Share Posted January 9, 2007 with the code given ;[code]$result=mysql_query("SELECT * FROM table");while($row=mysql_fetch_array($result)){ $total=$total+$row[cost];}[/code]Is their anyway i can have it rounded to it shows to the decimal point i.e. 50.00 insted of 50 Quote Link to comment Share on other sites More sharing options...
taith Posted January 9, 2007 Share Posted January 9, 2007 take a look at http://us2.php.net/manual/en/function.number-format.php that'd help ya out there :-) Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.