|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
MySQL 5 - WHERE on 2 clauses
I'm trying to figure out the best means of doing a querry but i'm stumped on the right syntax.
Basically i have a Field "Status" that can be either 0, 1, or 2. Only one record can have a value of 2 at a time so if a admin edits a record and sets it to 2, then all other instances of stattus = 2 are set to 1 Does this look good for my query? SET Status=1 WHERE ID <> '$ID' GROUP BY Status = 2
__________________
29 years of creative writing 13 years of HTML 10 years of Photoshop 6 years of PHP/MySQL And I never knew Photoshop could do HTML until 2004! You learn something new every day. |
|
#2
|
|||
|
|||
|
you don't need to group by anything. that is usually only for select statements. you can just say AND status=2
UPDATE Table SET Status=1 WHERE ID <> '$ID' AND Status = 2 |
|
#3
|
|||
|
|||
|
thanks, i'll give it a try!
So here is my final code for this bit, see any flaws? if ($Status == 2){$update = mysql_query("UPDATE ".$dtable." SET Status=1 WHERE ".$keyID." <> '$NewID' AND Status = 2")or die(mysql_error()); } Last edited by LLX : August 17th, 2009 at 01:30 PM. |
|
#4
|
|||
|
|||
|
looks fine.
|
|
#5
|
|||
|
|||
|
works well but a second set of eyes never hurt, thanks again for the help
|
![]() |
| Viewing: Codewalkers Forums > Other Technologies > Database Help > MySQL 5 - WHERE on 2 clauses |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|