sparkx 0 Report post Posted September 29, 2007 (edited) I cant get php to do simple math. Anyway I need to run a math problem from the mysql database (dont ask why). So lets say I have an entrie: 5+5. I get it from my db then eval it but nothing happens? How could I make it so that it runs the 5+5 rather then just displaying it?Thanks,SparkxAlso: I have no clue if it is just my browser or what but my post breaks to boarder for some odd reason? Edited September 29, 2007 by sparkx (see edit history) Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted September 30, 2007 I'm not really sure what you want but if it is to simply get the results of a math operation try this: <?php// math with 2 columns$sql="select (numeric_col1+numeric_col2) as result from table";$row=mysql_query($sql);$rs_row=mysql_fetch_array($row);echo $rs_row["result"];?>The above code only works if you want to perform the math operation with two columns, so, tell me, your entrie is like this or you have it in one column only.Also you can use the MySql CAST() function.Best regards, Share this post Link to post Share on other sites
sparkx 0 Report post Posted October 1, 2007 What I want is here is one column: 5+5 and I simply:echo($row['Column']);and that displayes 10 not 5+5. So the echo is:10I don't really know how else to say it. Im sorry if I am still a little confusing.Thanks,Sparkx Share this post Link to post Share on other sites
develCuy 0 Report post Posted October 2, 2007 What I want is here is one column: 5+5 and I simply:echo($row['Column']);and that displayes 10 not 5+5. So the echo is:10I don't really know how else to say it. Im sorry if I am still a little confusing.Thanks,Sparkx If you want PHP math:echo $row['Column']+5;If you want PHP + MySQL math:$rs = mysql_query("select 5+".5);print_r(mysql_fetch_row($rs));If you want MYSQL math:Select 5+5More on MySQL math.Blessings! Share this post Link to post Share on other sites
TavoxPeru 0 Report post Posted October 2, 2007 What I want is here is one column: 5+5 and I simply: echo($row['Column']); and that displayes 10 not 5+5. So the echo is: 10 I don't really know how else to say it. Im sorry if I am still a little confusing. Thanks, Sparkx Well, it took me more time than i expected but finally i got the solution, the way i got it is with the help of the php eval() function. What this function do is to evaluate the string given as a parameter as it is PHP code so you can execute it, i think it is very similar to the javascript eval() function. So please try the following code and tell us if it is what you want: <?phpeval("$"."variable"."=".$row['Column'].";");echo "\$variable is = $variable";//echo "<script>var var1=eval('$variable'); alert(var1);</script>";?>The last line -in case you need it- shows the use of the Javascript eval() function, simply uncomment this line to see it in action. Best regards, Share this post Link to post Share on other sites