Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Form determine which script to use based on a menu item?
Old 10-02-2009, 04:17 PM Form determine which script to use based on a menu item?
WebTraffic's Avatar
Extreme Talker

Posts: 225
Name: Brandon
Trades: 0
I am creating a calculator to determine a persons heating and cooling bill. Instead of having 1 really big script to calculate their bill based on which zone they are in, I want to create 5 separate scripts to do them.

Example:

PHP Code:
if(zone == 'Zone 1') {
use 
script for zone 1
}
if(
zone == 'Zone 2') {
use 
script for zone 2
}
if(
zone == 'Zone 3') {
use 
script for zone 3
}
if(
zone == 'Zone 4') {
use 
script for zone 4
}
if(
zone == 'Zone 5') {
use 
script for zone 5

Would I need to put this in the form action or would I have to redirect it? The problem I see with redirecting it is that the variables would lose their value as they were passed on to another page.
__________________

Please login or register to view this content. Registration is FREE

Coding is just like a woman. If you don't do something exactly right, it complains.
WebTraffic is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-02-2009, 04:59 PM Re: Form determine which script to use based on a menu item?
lizciz's Avatar
Webmaster Talker

Posts: 744
Name: Mattias Nordahl
Location: Sweden
Trades: 0
I dont know how your calculations would go about, but you could probably have just one script, and adjust a few values depending on the zone? Then you wouln't have to duplicate lots of code in each seperate script.

As a simplified example to show what I mean, lets say I want to calculate the cost of only electricity for different zones, and I know that if you live in zone1 each kWh costs 1 (dollar or something), in zone2 they cost 2 and in zone3 they cost 3.

I'll just put this value in my formula, as in
PHP Code:
switch($zone) {
   case 
'zone1':
      
$m 1;
      break;
   case 
'zone2':
      
$m 2;
      break;
   case 
'zone3':
      
$m 3;
      break;
   default:
      
$m 1;
      break;
}

$cost some_advanced_calculations() * $m
For your script maybe you'll need more than one variable $m. As I said, I dont know how your calculations would be like. But you could probably still set up some variables for each zone, so that they all could use the same calculation script.
__________________
34343639363436653237373432303635373837303635363337 34323037343638363137343263323036343639363432303739 366637353366

Last edited by lizciz; 10-02-2009 at 05:02 PM..
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 10-03-2009, 01:47 PM Re: Form determine which script to use based on a menu item?
WebTraffic's Avatar
Extreme Talker

Posts: 225
Name: Brandon
Trades: 0
Thanks I did this and it worked like a charm.
__________________

Please login or register to view this content. Registration is FREE

Coding is just like a woman. If you don't do something exactly right, it complains.
WebTraffic is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Form determine which script to use based on a menu item?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.13297 seconds with 12 queries