• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 433
  • Last Modified:

how to write php to get total bill

please suggest me how to write program form php to get to totlal Bill please show me code
thank

0
teera
Asked:
teera
  • 2
  • 2
2 Solutions
 
rwestonCommented:
Your question is very unclear.

If you were taking in a set of values though using a Form for example with fields, you could have page 1.htm:

<html>
<head>
<title>Untitled Document</title>
</head>

<body>
<form name="form1" method="post" action="total.php">
  <p>
    <input type="text" name="textfield">
</p>
  <p>
    <input type="text" name="textfield2">
  </p>
  <p>    <input type="text" name="textfield3">
  </p>
  <p>    <input type="text" name="textfield4">
  </p>
  <p>    <input type="text" name="textfield5">
</p>
  <p>
    <input type="submit" name="Submit" value="Submit">
</p>
</form>
</body>
</html>

total.php would contain:

<?
$total = 0;

foreach($_POST as $var => $value){

if(strstr($var,"textfield")){
$total += $value;
}

}

echo $total;

?>
0
 
jdpipeCommented:
Give some details of the type of problem you are trying to solve... are you writing a shopping basket system, or an accounting system, or do you just want add up some numbers?

JP
0
 
teeraAuthor Commented:
How can I use  PHP to get data form my sql Many tables and then  sum it Please give me a sample code
0
 
jdpipeCommented:
Teera it seems like you should probably go and do some basic reading. Please take a look at this introductory tutorial from WebMonkey - I found that site really useful when I was getting started:
http://webmonkey.wired.com/webmonkey/programming/php/tutorials/tutorial4.html

If you get through that then come back and ask a more focussed question, with exactly what you want to do, and for what purpose. Give an example of what you want it to look like, etc etc.
0
 
rwestonCommented:
Like jdpipe mentioned, some reading (esp. from the link is provided would help) and using the php manual as well would get you a solution.

What you're prety much looking for though is:

<?php
$total = 0;

$db = mysql_connect("localhost", "root");
mysql_select_db("mydb",$db);  //  replace mydb with the name of the database you want to use

$result = mysql_query("SELECT extendedcost  FROM orders",$db);

while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) {
   $total += $row["extendedcost"];
}

mysql_free_result($result);

From multiple tables, you could continue using the 'total' variable, run the same query against the other tables and just continue adding to total.
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now