Jump to content

Recommended Posts

Hello guys

 

I need to put together a calculator that I'm hoping you can help me with... It's a calculator that does/has the following

 

Fields -

(a)Application amount (constant to be changed only by administrator)Unit =ml/l

(b)Fuel Price (variable to be entered by user)Unit= Rands

©Fuel Usage (variable to be entered by user)Unit = l/month

(y)Cost of Item in Rands= (a x 0.132)

(z)Saving in Rands = ((b x c x 0.125) – y)

------------------------

 

It's going to be on a WordPress page so the value for (a) that I will change, will be a custom_field on one of the WP pages that I can go in & change. The user will insert his values for (b) and © and then the 2 calculation values will be (y) and (z)

 

The totals must be displayed in realtime as the user types.

 

Thanks very much for your help here :)

 

Regards

Mark

Link to comment
https://forums.phpfreaks.com/topic/125041-solved-php-calculator/
Share on other sites

What I thought would work is this:

 

<?php

 

$application_amount = 100;

$fuel_price = 9;

$fuel_usage = 10;

$naf-tech_cost = $application_amount * 0.132;

$rand_savings = (($fuel_price * $fuel_usage * 0.125) - $naf-tech_cost);

 

echo $rand_savings;

 

?>

 

But it didn't :P

 

Plus to the above, I must still add the 'realtime' calculation part...

 

<-- PHP Noob :P

 

Thanks for your help! :)

Ok cool I'll have a look at a JS option...

 

Would you mind providing me with the PHP solution to this on a page reload then to do the calculation? Leave JS out of the equation for this example.. How wold this calculation be done?

 

Thanks very much for your help :)

What I thought would work is this:

...

But it didn't

 

It's helpful to go beyond "didn't work" in your posts. What happened that you didn't expect? What didn't happen that you did expect? What did you see/not see? What error messages did you see? And so on ...

 

For starters, don't use hyphens in variable names as they're interpreted as subtraction operators. If you want easy-reading variable names, use underscore.

Also, there's no practical way to have it update on the fly with PHP. PHP is a server-side language. That means that the program is on the server, so the user needs to send their information to the server, the server processes it, and then the result is sent back to the user.

 

With javascript, the user (by downloading the page) downloads the program, enters their info, and the user's computer runs the program. Therefore, it can be run on the fly.

 

So, if you still only want to use PHP, you'll need to forget about the "on the fly" part.

Sorry I made that last reply regarding the URL on my mobile and guessed the URL... The correct URL is as follows:

 

http://designshowcase.co.za/share/calculate.php

 

Thanks

 

Also, there's no practical way to have it update on the fly with PHP. PHP is a server-side language. That means that the program is on the server, so the user needs to send their information to the server, the server processes it, and then the result is sent back to the user.

 

With javascript, the user (by downloading the page) downloads the program, enters their info, and the user's computer runs the program. Therefore, it can be run on the fly.

 

So, if you still only want to use PHP, you'll need to forget about the "on the fly" part.

 

i understand. what i'll do then, is have the user insert his 2 bits of information in a form, and then post to the page that does the calculation and displays the result. cool?

 

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.