I'm working on a script that takes all the values in a form, and calculates what it can based on which fields the user filed in.
I have created a rough outline, but don't know all of the correct syntax to use, especially the parts where it needs to go back to the begining, and the math functions.
If somone could correct the code for just one of the lines, I could probably figure out the rest from that.
thanks,
Nick
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>
</head>
<body>
<?PHP
//when the user clicks the calculate button, get these variables from the form fields, and start running the script
$HD;
$VD;
$TD;
$Dv;
$Dh;
$PC;
$FC;
$V;
$A;
$W;
$FA;
$MFv;
$MFh;
$GT1
$GT2
//begin executing the script
//we check to see if the user has filled in at least two variables
if at least two of the varibles are set {continue the script}else{die 'you must fill in at least two felds before calculating!!'};
//Check if when can solve for TD, or if TD was specified by the user.
if $TD isset {if $TD == anything thats not a number{die 'td must be a number!!'};
if $HD isset {if $HD == anything thats not a number{die 'hd must be a number!!'};
if $VD isset {if $VD == anything thats not a number{die 'vd must be a number!!'};
if user gives $HD and $VD and $TD {if $HD squared times $VD squared = $TD squared, do nothing and continue the script
}else{die "We're sorry, but you can't change the laws of physics!"};
// solve for TD
if user gives $HD and $VD and NOT $TD {solve for $TD, and set $TD = the answer};
if user gives $TD and not $VD and not $HD {continue running the script};
//check if TD, MF, and D exist, and if they are numbers
if $TD isset {if $TD == anything thats not a number{die 'td must be a number!!'};
if $Dv isset {if $Dv == anything thats not a number{die 'd must be a number!!'};
if $Dh isset {if $Dh == anything thats not a number{die 'd must be a number!!'};
if $MFh isset {if $MFh == anything thats not a number{die 'mfh must be a number!!'};
if $MFv isset {if $MFv == anything thats not a number{die 'mfv must be a number!!'};
//check for and solve possible variances of d = mf * td for the verticle axis
if the user is stupid and gives us Dv and MFv and TD {we chack to see if dv=mfv*TD, and if it does, we ignore it, and continue} else {die 'We remind them that physics cannot be altered!!!'};
if we have TD and MFv and not Dv {solve for D using MFv * TD and set $Dv = to the answer}
else if we have TD and Dv and not MFv {solve for MFv using D / TD and set $mfv = to the answer}
else if we have Dv and MFv and not TD {solve for TD using Dv /MFv and set $TD = to the answer};
//check for and solve possible variances of d = mf * td for the horizontal axis
if we have TD and MFh and not Dh {solve for Dh using MFh * TD and set $Dh = to the answer};
if we have TD and Dh and not MF {solve for MFh using Dh / TD and set $mfh = to the answer};
if we have Dh and MFh and not TD {solve for TD using Dh /MFh and set $TD = to the answer};
if the user is stupid and gives us Dh and MFh and TD {we chack to see if dh=mfh*TD, and if it does, we ignore it, and continue} else {die 'We remind them that physics cannot be altered!!!'};
//we check if we have FA, and if it's a number (we already know MF is a number, or we would have died)
if $FA isset {if $FA == anything thats not a number{die 'FA must be a number!!'};
//we solve for variances of mf=2 x TAN (FA/2)
if we have MF and not FA {we solve for FA, and set $FA = to the answer};
if we have FA and not MF {we solve for MF, and set $MF = to the answer};
//if we have MF now and didn't before, we go back to the top of the script (where is says 'begine executing the script'), and run it again now that we have a new variable set
if we have MF now and didnt before {go back to top and run again with the new variable};
//we check and see if we have pc and if its a number
if $PC isset {if $PC == anything thats not a number{die 'pc must be a number'};
//conver the gel transmission rates from percents to decimals, if they exist
if $GT1 {we convert the percent entered by the user to a decimal and save it to $GT1};
if $GT2 {we convert the percent entered by the user to a decimal and save it to $GT2};
// if we can, we consider the gel transmission before going on
if $FC isset and $PC !isset {
if $FC and $GT1 and not $GT2 isset {solve for $PC using FC/$GT1=$PC and save the answer as $PC
}else if{ $FC and $GT2 and not $GT1 isset {solve for $PC using FC/$GT2=$PC and save the answer as $PC
}else if{ $FC and $GT1 and $GT2 isset {solve for $PC using FC/$GT2/$GT1=$PC and save the answer as $PC};
if $FC and $GT1 isset {multiple $FC by $GT1 and save the answer as $FC}
if $FC and $GT2 isset {multiple $FC by $GT2 and save the answer as $FC}
//we solve for variances of fc= pc /(tdv squared)
if we have PC and TD and not FC {we solve for PC, and set $PC = to the answer and if $GT1 isset {we multiply the new $FC by $GT1 and store the answer as $FC} and if $GT2 isset, we multiple $FC by $GT2 as well, and agin, store the answer as $FC
}else if we have FC and TD and not PC {we solve for PC, and set $FC = to the answer
}else if we have PC and FC and not TD {we solve for TD and set $TD = the answer
}else if we dont have PC and dont have FC and dont had TD {we ignore this set, and carry on
}else if we have TD and FC and PC {if FC and PC and TD calculate out corectly {carry on}else{die 'physics cannot be changed'};
//if we have TD now and didn't before, we go back to the top of the script (where is says 'begine executing the script'), and run it again now that we have a new variable set
if we have TD now and didnt before {go back to top and run again with the new variable};
//Now that we have out answers, lets spit them out, and go to bed, since it's 4 AM
if $MFv isset {spit it out into the approprate field on the form];
if $MFh isset {spit it out into the approprate field on the form];
if $GT1 isset {spit it out into the approprate field on the form];
if $GT2 isset {spit it out into the approprate field on the form];
if $HD isset {spit it out into the approprate field on the form];
if $VD isset {spit it out into the approprate field on the form];
if $TD isset {spit it out into the approprate field on the form];
if $Dv isset {spit it out into the approprate field on the form];
if $Dh isset {spit it out into the approprate field on the form];
if $PC isset {spit it out into the approprate field on the form];
if $FC isset {spit it out into the approprate field on the form];
if $FA isset {spit it out into the approprate field on the form];
if $V isset {spit it out into the approprate field on the form];
if $A isset {spit it out into the approprate field on the form];
if $W isset {spit it out into the approprate field on the form];
?>
</body>
</html>