markbloomfield Posted September 20, 2008 Share Posted September 20, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/ Share on other sites More sharing options...
F1Fan Posted September 20, 2008 Share Posted September 20, 2008 Do you have any code so far, or are you looking for some pre-written stuff? Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-646179 Share on other sites More sharing options...
markbloomfield Posted September 20, 2008 Author Share Posted September 20, 2008 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 Plus to the above, I must still add the 'realtime' calculation part... <-- PHP Noob Thanks for your help! Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-646180 Share on other sites More sharing options...
F1Fan Posted September 20, 2008 Share Posted September 20, 2008 If you need something to calculate in real-time, JavaScript would be your best bet. With JS, you could add an "onkeyup" event to each input field that ran the JS function to recalculate. Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-646184 Share on other sites More sharing options...
markbloomfield Posted September 20, 2008 Author Share Posted September 20, 2008 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 Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-646294 Share on other sites More sharing options...
AndyB Posted September 20, 2008 Share Posted September 20, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-646318 Share on other sites More sharing options...
markbloomfield Posted September 20, 2008 Author Share Posted September 20, 2008 heya you can see the error here www.designshowcase.co.za/share/calculator.php tx Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-646342 Share on other sites More sharing options...
LemonInflux Posted September 20, 2008 Share Posted September 20, 2008 Not Found The requested URL /share/calculator.php was not found on this server. Apache/2.2.0 (Fedora) Server at www.designshowcase.co.za Port 80 Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-646358 Share on other sites More sharing options...
F1Fan Posted September 21, 2008 Share Posted September 21, 2008 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. Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-646838 Share on other sites More sharing options...
markbloomfield Posted September 22, 2008 Author Share Posted September 22, 2008 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? Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-647506 Share on other sites More sharing options...
markbloomfield Posted September 22, 2008 Author Share Posted September 22, 2008 Nevermind, I have it working Thanks for your comments! Quote Link to comment https://forums.phpfreaks.com/topic/125041-solved-php-calculator/#findComment-647554 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.