sparkx
Sep 29 2007, 11:18 PM
| | 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? |
Reply
TavoxPeru
Sep 30 2007, 08:52 AM
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,
Reply
sparkx
Oct 1 2007, 10: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
Reply
develCuy
Oct 2 2007, 02:48 AM
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!
Reply
TavoxPeru
Oct 2 2007, 04:30 AM
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 "<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,
Reply
Recent Queries:--
php mysql cast function - 1.79 hr back. (1)
Similar Topics
Keywords : php, math, error
- Php Configuration Error?
(6)
Cant Find The Error
(2) In this code I want to retrieve the energy and max energy of a players account, then add 8% to
energy of maxenergy, hen if energy is bigger than maxenergy, energy is then made equal to maxenergy.
Then the database is updated. I don't understand why it's not working.
$query=mysql_query("SELECT MAX(id) as maxid FROM `accounts` LIMIT 1"); $row =
mysql_fetch_assoc($query); $id = $row ; $query = "SELECT * FROM `accounts`";
$result=mysql_query($query); while ($row=mysql_fetch_assoc($result)) { $energy = $row ; $maxenergy
= $row ; } for($i=1; $i $query = "SELECT....
Php Error-where To Put "?>"
(2) lol....lately i have many problems in writing my scripts and i dont know if i should create post
only for purpose so ppl can help me or should i create many post like i am doing right now...i am
NOT making this to get many credits...i am doing it because i need help and many people here help
me! CODE if ($_GET !='race'){ Who do you wanna race? Derbi Senda 50
Honda NS 50 R Suzuki ZR 50 Yamaha DT 50 MX Aprilia RS 50 - ?
} i have this code...if i put after it i get QUOTE Parse error: syntax....
Warning: Mysql_num_rows()
What is the error :S (1) Hey! I've made a register script.. Some time ago it worked. And I ain't sure if I changed
something since then.. The error I am getting is this: Warning: mysql_num_rows(): supplied argument
is not a valid MySQL result resource in /home/feelay/public_html/regcheck.php on line 31 Here is
the code on theese lines: CODE $sqlCheckForDuplicate = "SELECT username FROM user WHERE username
= '". $username ."'"; if( mysql_num_rows( mysql_query(
$sqlCheckForDuplicate ) ) == 0 ) { $sqlRegUser = "INSERT INTO ....
Unexpected Error
Undefined variable??? (2) Is this script correct? index.php : CODE if (isset($_COOKIE )) $_GET =
$_COOKIE ; else setcookie("disp_name", Anonymous, date()+99); ?>
Display Name - DZN
Dislpay Name: name="name" />
proccess.php : CODE Proccessing Request... Please wait...
setcookie("disp_name", $_GET , date()+99); ?> main.php : CODE function customErr....
Error On Submit Page
(10) I am writing a new submit page for one of my sites and am doing a few things to stretch my
experience. I am getting an error (naturally.) Here is part pf the page where the error might be:
CODE //Check to see if the web page called itself if (strtoupper($action) == "CHECK") {
//The web page called itself, so run the error checking code //Declare a variable to
hold the error messages $error = ''; // variable names: name, cat, sub_cat, url,
date, status, email, other, area_code, city $name = $_POST ; $cat = $_P....
Got A Wee Error - Can You Help?
(13) I'm taking a PHP course at college and am working on an assignment. There's no database
involved. I've declared my variables from a submit form on another page, and on the page
I'm working on I'm trying to bring them up in a table. But my start-table command is
outputting an error. Here's the code relating to where the error is: CODE //Get First
Item if (isset($_GET )) { $item_1_product = $_GET ; } else {
$item_1_product = ""; //Default value if data missing } if (isset($_GET ))
{ ....
E-mail List Error
(4) I just coded this e-mail list, it works well for entering data into database, but if user leaves
the field blank or adds an already exist e-mail it gives him the error message and stops loading the
rest of the page. CODE // Connects to your Database mysql_connect("localhost", "my_username",
"mypassword") or die(mysql_error()); mysql_select_db("Database name") or die(mysql_error()); //This
code runs if the form has been submitted if (isset($_POST )) { //This makes sure they did not leave
any fields blank if (!$_POST ) {die(' No e-mail added '); } ....
In Php, How To Not Display Mysql Connection Error?
Don't want mysql_connect() message (4) In PHP, if the mysql database server cannot be connected, for example database server is handed or
turned off, an error message will be displayed: Warning: mysql_connect(): Unknown MySQL Server Host
"mysql.example.com" ... My question is how to not display this warning message? or can I customise
the error message? if so, how? Thank you.....
Php Problem Error Message
I'm working from a book (9) I get this error message when I try to view a small webpage. QUOTE Parse error: parse error,
unexpected T_STRING, expecting ',' or ';' in
/home/nilsc/public_html/bobs/processorder.php on line 27 Line 27 is in this php part: CODE
echo ' Order processed. '; echo $tireqty. ' tires '; echo $oilqty. ' bottles
of oil '; echo $sparkqty. ' spark plugs '; $totalqty = 0; $totalqty = $tireqty +
$oilqty + $spakqty; echo 'Items ordered: ' .$totalqty.' ; $totalamount = 0.00;
define('TIREPRICE....
PHP paFileDB error
an error relating to admin login (0) does any body know how to over come an error in paFileDB which says Warning: Cannot modify header
information - headers already sent by (output started at
/home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
/home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 36 Warning: Cannot modify
header information - headers already sent by (output started at
/home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
/home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 38 i have downloaded the php
from phparena.net directly. Any hel....
PHP paFileDB error
an error relating to admin login. (2) does any body know how to over come an error in paFileDB which says Warning: Cannot modify header
information - headers already sent by (output started at
/home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
/home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 36 Warning: Cannot modify
header information - headers already sent by (output started at
/home/paltalkh/public_html/pafiledb/includes/mysql.php:86) in
/home/paltalkh/public_html/pafiledb/includes/admin/login.php on line 38 i have downloaded the php
from phparena.net directly. Any he....
Looking for php, math, error
|
*SIMILAR VIDEOS*
Searching Video's for php, math, error
|
advertisement
|
|