How to introduce a php variable into an MySQL calculation?

me_patrick
me_patrick used Ask the Experts™
on
I want to set a field (column) with a new value partly based on the result of a calculation in php, e.g.   .... SET order_total      = (order_total + $adjustment) .....
but this didn't seem to work - how can I make that dynamic calculation work within the MySQL UPDATE statement?  
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Here is an example where $email is the variable
 

$sql = "SELECT `email`, `contactme` FROM `your_table` WHERE `email` = '$email' and `contactme` = '1'";

Open in new window

Commented:
Ignore my previous post, didn't read the whole question.
Your going to have to calculate the adjustment from the order_total before inserting into the database. Something like:
$newtotal = order_total + $adjustment
Set order_total = $newtotal
Commented:
$nr=12;
mysql_query("UPDATE cikk SET sorszam=(sorszam+'".$nr."') where id_cikk='11'");

Author

Commented:
That's it - thanks.

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial