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

teeraAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

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

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
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
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
PHP

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.