Web Analytics Made Easy -
StatCounter Help with php calculator result output. - CodingForum

Announcement

Collapse
No announcement yet.

Help with php calculator result output.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with php calculator result output.

    Hi,

    Relatively new to php but am finding it quick to get results with it. One thing I have some trouble with is making the output of a php result display on the same form.

    A screen shot of the calculator interface is shown bellow :

    http://img.photobucket.com/albums/v5...tofphpcalc.jpg

    After entering all relevant data in the form and clicking on the CALCULATE button I would like the result to be displayed in the box below, Total Freight Cost : TEST is shown. Then I can keep entering other form input data and display results again and again on the same page.

    Not many tutorials I have come across discuss anything like this so I hope somebody can point out to me an easy way of doing this with php and html scripts etc.

    Thanks in advance, Mike

  • #2
    calculate a result and print it in that place it is simple
    Free php image upload script
    Personal web developing blog

    Comment


    • #3
      Originally posted by kreoton View Post
      calculate a result and print it in that place it is simple
      It might be simple, but a simple example might be good to explain how to print in HTML to a praticular position in a table. I guess I don't know that as I've never had to do it and don't spend a great deal of time writing HTML code anyways ...

      Cheers, Mike

      Comment


      • #4
        in example you calculated resilt in variable $result, place it where you whant in table
        PHP Code:
        <td><?php echo $result?></td>
        or in input tag

        PHP Code:
        <input type="text" name="result" value="<?php echo $result?>" >
        Free php image upload script
        Personal web developing blog

        Comment


        • #5
          Originally posted by kreoton View Post
          in example you calculated resilt in variable $result, place it where you whant in table
          PHP Code:
          <td><?php echo $result?></td>
          or in input tag

          PHP Code:
          <input type="text" name="result" value="<?php echo $result?>" >
          Hi, thanks for the reply. Under normal circumstances that would probably work if the php calculator code was embedded with the rest of the html table etc. but in this case the form action requires calling an external php file eg :

          <form ACTION="hx_calc.php" onsubmit="return validate_form(this)" method="POST" name="CALCULATE">
          <table border="0" cellpadding="5" cellspacing="5" height="226">
          <tr>
          <td height="42">
          <font face="Verdana">Enter Destination Postcode : </font>
          <INPUT TITLE="Enter a valid Destination Postcode" TYPE="text" NAME="postcode" SIZE="3" STYLE="background:F5F5F5" tabindex="1">
          ....
          ...
          ..

          When the calculate button is pressed the form first validates the entered values (sanity check via javascript) then passes the form values to another file, hx_calc.php, executing the php code and doing the number crunching to obtain the final value in $freight_cost. So basically there is no table to place anything into ?!?

          This is where I'm a little confused. Once the hx_calc.php file has been processed, how does it return to the original html file that called it ?!? The original file has the table etc. Just placing a <?php echo $freight_cost; ?> in the table at the position required doesn't display anything, because the <form ACTION="hx_calc.php" .... tag calls the other file hx_calc.php on a different wepage, once the CALCULATE button is pressed.

          It would seem like this should be a simple thing to do but I must be missing some details or insight into getting it working with a simple solution.

          Cheers, Mike

          Comment


          • #6
            ok you have a result in varibale $freight_cost so include form in yours hx_calc.php file and and place echo where you whant
            Free php image upload script
            Personal web developing blog

            Comment


            • #7
              This is where I'm a little confused. Once the hx_calc.php file has been processed, how does it return to the original html file that called it ?!?
              That is a good question We'd need to see the code in hx_calc.php that causes a return to the original page, because there are many ways this can be done. My favorite is using the header(Location) function, but I've seen other ways too.

              There are also numerous ways to send data from hx_calc.php to your first page. You can stuff a value in the URL (called a query string) such as hx_display.php?cost=45, you can set a cookie, you can send a form action with POST method (don't really recommend that one) or you can use sessions and pass data back and forth using the $_SESSION global variable (probably overkill for your needs).

              Comment


              • #8
                Originally posted by kreoton View Post
                ok you have a result in varibale $freight_cost so include form in yours hx_calc.php file and and place echo where you whant
                Ok have included the entire table and form code in the hx_calc.php file and now the result is displayed where it is required. It is a solution, however the settings in the drop down menues and any entered input values are gone once the result is displayed. I think I will have to look into a few other alternatives solutions like passing the $freight_cost value back to the original form page, if this is possible at all.

                Thanks heaps for your help !!

                Cheers, Mike

                Comment


                • #9
                  Originally posted by Fumigator View Post
                  That is a good question We'd need to see the code in hx_calc.php that causes a return to the original page, because there are many ways this can be done. My favorite is using the header(Location) function, but I've seen other ways too.

                  There are also numerous ways to send data from hx_calc.php to your first page. You can stuff a value in the URL (called a query string) such as hx_display.php?cost=45, you can set a cookie, you can send a form action with POST method (don't really recommend that one) or you can use sessions and pass data back and forth using the $_SESSION global variable (probably overkill for your needs).
                  Thanks, will look into the sessions method of passing data back to the original page.

                  Cheers, Mike

                  Comment

                  Working...
                  X