|
|
|
| Web Hosting |
![]() ![]() |
Php Math Error |
Sep 29 2007, 11:18 PM
Post
#1
|
|
|
Sparkx Group: [HOSTED] Posts: 371 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 myCENTs:0.61 |
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, Sparkx Also: I have no clue if it is just my browser or what but my post breaks to boarder for some odd reason? This post has been edited by sparkx: Sep 29 2007, 11:19 PM |
|
|
|
Sep 30 2007, 08:52 AM
Post
#2
|
|
|
Super Member Group: [HOSTED] Posts: 818 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:3.57 |
I'm not really sure what you want but if it is to simply get the results of a math operation try this:
CODE <?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, |
|
|
|
Oct 1 2007, 10:55 PM
Post
#3
|
|
|
Sparkx Group: [HOSTED] Posts: 371 Joined: 11-October 06 From: Dana Point, CA, USA Member No.: 16,496 myCENTs:0.61 |
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 |
|
|
|
Oct 2 2007, 02:48 AM
Post
#4
|
|
|
Member - Active Contributor Group: Members Posts: 88 Joined: 5-April 07 From: Cusco - Peru Member No.: 21,283 |
QUOTE(sparkx @ Oct 1 2007, 05:55 PM) [snapback]111715[/snapback] 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 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+5 More on MySQL math. Blessings! |
|
|
|
Oct 2 2007, 04:30 AM
Post
#5
|
|
|
Super Member Group: [HOSTED] Posts: 818 Joined: 8-April 06 From: Lima - Peru Member No.: 12,579 myCENTs:3.57 |
QUOTE(sparkx @ Oct 1 2007, 05:55 PM) [snapback]111715[/snapback] 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: CODE <?php eval("$"."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, |
|
|
|
![]() ![]() |
1 User(s) are reading this topic (1 Guests and 0 Anonymous Users)
0 Members:
Similar Topics
| Topic Title | Replies | Topic Starter | Views | Last Action | |||
|---|---|---|---|---|---|---|---|
![]() |
5 | derouge | 1,536 | 30th November 2008 - 07:16 AM Last post by: iG-Rev.Keith Ratliff |
|||
![]() |
2 | xboxrulz | 232 | 3rd November 2008 - 12:00 AM Last post by: xboxrulz |
|||
![]() |
6 | xboxrulz | 211 | 23rd October 2008 - 06:44 PM Last post by: xboxrulz |
|||
![]() |
6 | Gollum | 1,287 | 13th October 2008 - 04:05 PM Last post by: Mordent |
|||
![]() |
5 | skedad | 373 | 12th October 2008 - 05:24 AM Last post by: skedad |
|||
![]() |
0 | khalilov | 203 | 5th September 2008 - 08:14 PM Last post by: khalilov |
|||
![]() |
6 | Eggie | 1,164 | 24th August 2008 - 10:12 PM Last post by: Guest |
|||
![]() |
2 | mingkus | 197 | 21st August 2008 - 06:20 PM Last post by: wutske |
|||
![]() |
2 | Gr33nN1nj4 | 290 | 20th August 2008 - 01:25 AM Last post by: Gr33nN1nj4 |
|||
![]() |
0 | rahulappe | 326 | 1st August 2008 - 08:48 AM Last post by: rahulappe |
|||
![]() |
8 | hihihihi88 | 1,843 | 30th July 2008 - 09:48 PM Last post by: Guest |
|||
![]() |
5 | LuPPy | 972 | 22nd July 2008 - 11:37 AM Last post by: Guest |
|||
![]() |
6 | ajayshivaa | 1,550 | 19th July 2008 - 01:58 AM Last post by: Guest |
|||
![]() |
7 | LacrosseMS | 792 | 4th July 2008 - 09:12 PM Last post by: TavoxPeru |
|||
![]() |
5 | Miles | 937 | 3rd July 2008 - 02:46 PM Last post by: tansqrx |
|||
|
Lo-Fi Version | Time is now: 8th January 2009 - 01:06 AM |
© 2009 AstaHost: Free Web Hosting & Technical Discussion, Free Web Hosting. a member of xisto.
Powered by Invision Board. Skin: IPB Forum Skins
Expand / Collapse Navigation



Sep 29 2007, 11:18 PM




