Jump to content

Recommended Posts

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

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:)

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.