English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

Hi,

I am working with PHP 5 and MYSQL (most current version, although Im not sure of the number of the top of my head). My problem is this...

I would like to update TWO DB fields at once... Right now, I have this:

$mystatement="UPDATE mytable SET myfield1=myfield1+1 WHERE ID='id_number'";

Now... This works just fine and updates "myfield1" by adding 1(incrementing) to the current myfield1 value. BUT... In my script, I will occasionally be resetting the "myfield1" value to ZERO, BUT I would still like to track the total from it, in another field -- "myfield2".

Is there a statment that will allow me to update (increment) both myfield1 and myfield2 at the same time? Something like...

$mystatement="UPDATE mytable SET myfield1=myfield1+1 AND SET myfield2=myfield2+1 WHERE ID='id_number'";

Please help, thanks.

2006-12-23 07:58:21 · 4 answers · asked by Player 1 2 in Computers & Internet Programming & Design

4 answers

This should work..........you don't need to do this in two statements at another user stated.........

update YourTable set YourFirstField=Variable1, YourSecondField = Variable2 where SomeField=SomeValueVariable

the variables can be replaced a literal (quoted text) or a numeric where appropriate if needed.

2006-12-23 09:07:28 · answer #1 · answered by Jeffrey F 6 · 0 0

$mystatement="UPDATE mytable SET myfield1=myfield1+1 WHERE ID='id_number'"; UPDATE mytable SET myfield2=myfield2+1 WHERE ID='id_number';"

2006-12-23 08:02:39 · answer #2 · answered by Anonymous · 0 1

The good replace v2.10 replaced into the important one bringing voice changer e.t.c. replace v2.seventy one is an upload on to that providing more suitable stability with some titles (a lot less freezing or "bypass-sluggish") and makes it a lot less in all probability so that you may be disconnected at the same time as taking section in on line video games, perfect once you're interior the midst of a Timeshift killing spree, or about to nail a Christ Air in Skate! This replace also made a minor progression for your BluRay (or "BD") participant, allowing image In image on all BluRay videos, besides as updating the PS3 so it ought to play all the hot BD releases, so no discs are too good on your gadget! desire I helped! - d23

2016-12-01 03:05:11 · answer #3 · answered by marconi 4 · 0 0

Yes, you should be able to do this...

UPDATE mytable (myfield, myotherfield) VALUES (myfield+1, myotherfield+1) WHERE ID='id_number'

I've never tried it, but I believe that should work.

2006-12-23 08:20:01 · answer #4 · answered by GrayTheory 4 · 0 1

fedest.com, questions and answers