A process can be solved by using a mathematical equation (simple polynomial of degree <=4). Different equations are to be used depending on the circumstances of the situation. The different equations that can be used for each circumstance are stored as VARCHAR entries in a mySQL table.
Here's what I want to do:
1. pull equation out of mySQL and store it in a variable (as a string?)
2. The equation is a function of one variable: "x", so assign some variable in my script to be $x="x"
3. Solve the equation and get an output variable.
Here is how I would think to do it (probably incorrectly), see if you have a better idea:
Code: Select all
//query the equation
$sql="SELECT equation FROM table WHERE id=3";
$result=mysql_query($sql) or die(mysql_error());
$equation=mysql_fetch_result($result,0,0);
//the equation now stored in $equation is this: "21 + pow(123*$x,2) + pow(1234*$x,3) "
//assign a value to $x
$x=2;
//form an equation, which I want to give me an outcome
$outcome = $equation;
//print the result of the calculation
print"Result = $outcome";
//should print: "Result = 10385"