Silverado_NL Posted March 28, 2007 Share Posted March 28, 2007 hi everyone. i am currently making a website with a certain switch that goes 2 ways, On and Off , handled by 1 and 0 now i have this query to handle and switch this value $query ="UPDATE table SET switch = IF(switch = '0', '1', IF(switch = '1', '0', switch)) WHERE record_id = $record_id"; but a 3rd value is needed now. but how do i check this in the query???? INSTEAD OF: logical query being, ::::: if switch == 0 then make 1 , if switch == 1 then make 0 it now needs to be like this, :::::::::: if switch == 0 then make 1 , if switch == 1 then make 2 , if switch == 2 then make 0 does anybody have any idea???? i cant find any info on If statement in query's on the internet. so i thought ill ask here:):) thanks in advance... Silverado Link to comment https://forums.phpfreaks.com/topic/44620-solved-mysql-if-statement-in-query/ Share on other sites More sharing options...
Silverado_NL Posted March 28, 2007 Author Share Posted March 28, 2007 already solved:) i wrote this query. db_query("UPDATE table SET switch = IF(switch = '0', '1', IF(switch = '0', '1', IF(switch = '1', '2', IF(switch = '2', '0', switch)))) WHERE record_id = $record_id"); i had the table record settings on Enum '0','1' instead of Enum '0','1','2' !!!!!!!!!!!!!!! that's why it didnt work at first, and i thought i wrote the query on a wrong way. thanks anyways:) Link to comment https://forums.phpfreaks.com/topic/44620-solved-mysql-if-statement-in-query/#findComment-216691 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.