keepAway Posted May 11, 2011 Share Posted May 11, 2011 How can i do the sum of two numbers inside of a mysql quory, or if this is possible? while($rand = mysql_fetch_array($cerereSQL)) { $pctsteaua = $rand['puncte']; echo "<pre>"; print_r ($rand); echo "</pre>"; } First i have this variable $pctsteaua who will return me a number. This number i need to use it here. mysql_query ("UPDATE liga1 SET puncte='$pctsteua + 3', m='1', v='1' WHERE echipa='Steaua' "); The problem is, how i do the math inside this myslq quory to work properly and update my database not with a submited number, but with the sum between the $pctsteaua variable + 3. Quote Link to comment https://forums.phpfreaks.com/topic/236158-mysql-question/ Share on other sites More sharing options...
socratesone Posted May 12, 2011 Share Posted May 12, 2011 I haven't tried this, but I suggest you do: mysql_query ("UPDATE liga1 SET puncte=($pctsteua + 3), m='1', v='1' WHERE echipa='Steaua' "); note - don't need quotes if puncte is an int, and mathematical expressions should be enclosed in parenthesis. Quote Link to comment https://forums.phpfreaks.com/topic/236158-mysql-question/#findComment-1214219 Share on other sites More sharing options...
gizmola Posted May 12, 2011 Share Posted May 12, 2011 Put a php block around the expression you want to evaluate. mysql_query ("UPDATE liga1 SET puncte='{$pctsteua + 3}', m='1', v='1' WHERE echipa='Steaua' "); Quote Link to comment https://forums.phpfreaks.com/topic/236158-mysql-question/#findComment-1214233 Share on other sites More sharing options...
keepAway Posted May 12, 2011 Author Share Posted May 12, 2011 Thanks for the answers, i eventually realized how to do it after lots of attempts. mysql_query ("UPDATE liga1 SET puncte='$pctsteaua'+'3', m='$msteaua'+'1', v='$vsteaua'+'1' WHERE echipa='Steaua' "); Quote Link to comment https://forums.phpfreaks.com/topic/236158-mysql-question/#findComment-1214247 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.