how to write php to get total bill

Posted on 2004-11-27
Last Modified: 2008-03-06
please suggest me how to write program form php to get to totlal Bill please show me code

Question by:teera
    LVL 1

    Accepted Solution

    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:

    <title>Untitled Document</title>

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

    total.php would contain:

    $total = 0;

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

    $total += $value;


    echo $total;

    LVL 7

    Expert Comment

    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?


    Author Comment

    How can I use  PHP to get data form my sql Many tables and then  sum it Please give me a sample code
    LVL 7

    Assisted Solution

    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:

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

    Expert Comment

    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:

    $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"];


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

    Featured Post

    How your wiki can always stay up-to-date

    Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
    - Increase transparency
    - Onboard new hires faster
    - Access from mobile/offline

    Join & Write a Comment

    Author Note: Since this E-E article was originally written, years ago, formal testing has come into common use in the world of PHP.  PHPUnit ( and similar technologies have enjoyed wide adoption, making it possib…
    I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
    The viewer will learn how to dynamically set the form action using jQuery.
    The viewer will learn how to count occurrences of each item in an array.

    745 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    16 Experts available now in Live!

    Get 1:1 Help Now