Jump to content

Math problem


Ifa

Recommended Posts

$var = 1;
mysql_query("UPDATE table SET var=var+'$var' FROM somewhere");

For some reason only Internet Explorer makes the math correct, other browsers always return a bit higher number than they should (ie 1+1 = 5). I'm quite lost...
Link to comment
Share on other sites

try it without the single quotes, since you're dealing with adding integers. as for the difference between browsers, that doesn't make much sense to me, since the math is being handled by the server. is the variable being populated from a form field, or when you run the code just as you have it, is it off? next question: why do you have a FROM clause in an update statment? what are you trying to do? shouldn't it be a WHERE?
[code]
<?php
$var = 1;
mysql_query("UPDATE tableName SET var = var + $var WHERE something = something");
?>
[/code]
Link to comment
Share on other sites

Oops, your right about the from, I use where, I just wrote the code as an example and made a tiny mistake :)

No, the data isn't coming from a form, it's a number that is increased in a loop. But thanks, I'll try it without no single quotes. I can test it now though, as I'm at work, and all this comp has is IE...

To be more spesific, the number is a calculation actually, $var = round($var2 / $var3, 0);
Link to comment
Share on other sites

This is getting funny:
$var = $var2 + 10;
mysql_query("UPDATE table SET var = $var WHERE some=thing ") or die('Query failed: ' . mysql_error());
echo $var;

the echo returns 16, but the update makes it 18... And though it seems extremely odd, IE just makes it right, and firefox doesn't. So much for it being a serverside language ;)

$var2 = -1 * round(($var3 * $var4) / $var5, 0);

Oh and with  or without ' ' seems to make no diffrence...
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.