Welcome Guest ( Log In | Register )



 
Reply to this topicStart new topic
> Php Math Error
sparkx
post Sep 29 2007, 11:18 PM
Post #1


Sparkx
Group Icon

Group: [HOSTED]
Posts: 354
Joined: 11-October 06
From: Dana Point, CA, USA
Member No.: 16,496



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
Go to the top of the page
 
+Quote Post
TavoxPeru
post Sep 30 2007, 08:52 AM
Post #2


Super Member
Group Icon

Group: [HOSTED]
Posts: 763
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



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,
Go to the top of the page
 
+Quote Post
sparkx
post Oct 1 2007, 10:55 PM
Post #3


Sparkx
Group Icon

Group: [HOSTED]
Posts: 354
Joined: 11-October 06
From: Dana Point, CA, USA
Member No.: 16,496



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
Go to the top of the page
 
+Quote Post
develCuy
post Oct 2 2007, 02:48 AM
Post #4


Member - Active Contributor
Group Icon

Group: Members
Posts: 88
Joined: 5-April 07
From: Cusco - Peru
Member No.: 21,283



QUOTE(sparkx @ Oct 1 2007, 05:55 PM) *
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!
Go to the top of the page
 
+Quote Post
TavoxPeru
post Oct 2 2007, 04:30 AM
Post #5


Super Member
Group Icon

Group: [HOSTED]
Posts: 763
Joined: 8-April 06
From: Lima - Peru
Member No.: 12,579



QUOTE(sparkx @ Oct 1 2007, 05:55 PM) *
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 "&lt;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,
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Error 406 - Problem In My Phpbb Forum(8)
  2. Send Mail Through Outlook Express(7)
  3. Help Needed: Monitor Out Of Timing(6)
  4. Grub Error After Reinstalled Winxp(11)
  5. Anyone Into The Number 11 ?(10)
  6. Windows XP Error: Explorer Crashes While Drag & Drop(14)
  7. Dreamweaver 8 Issue(9)
  8. Bsod Error & It's Causes(6)
  9. Magic Nine?(4)
  10. Itunes Album Art(6)
  11. Warning: Mysql_num_rows()(1)
  12. Bid For Power Opengl Error [solved](6)
  13. Lost Connection To Mysql ,..., System Error: 111 In(3)
  14. Java Applet Loading Error(5)
  15. Sql Syntax Error [corrected](2)
  1. Php Error-where To Put "?>"(2)
  2. My First Google Error(8)
  3. Calendar And The Date () Function(0)
  4. Strange Error When Trying To Install Fedora Core 9(5)
  5. Linux Basic Command - For Storing Compilation Error To File(1)
  6. I Have An Error With My Mysql Connection(7)
  7. Mysql Storage Engine Error 28(5)
  8. Common Ftp Server Error Codes(0)
  9. Error Connecting To Domain(2)
  10. Cant Find The Error(2)
  11. Purchase Credit Error(0)
  12. Cpanel Error When Loggin In...(4)
  13. Ffow: Frontlines: Fuel Of War(1)


 



- Lo-Fi Version Time is now: 11th October 2008 - 05:03 AM