Jump to content

[SOLVED] Active Row?


madhatter301

Recommended Posts

Hi,

 

I have an sql table with various fields in, one of which is "Active" which is an enum 'y' or 'n'. Basically This table holds different events, of which only 1 may be active at one time. So my question is, is their an easier/better way of doing this kind of thing. At the moment I have to check all rows in the table to find which one has active set to 'y', then if i want to change it, set it to 'n' and set the new row i want active to 'y'. Any advice on this would be appreciated.

 

Thanks

Link to comment
https://forums.phpfreaks.com/topic/42101-solved-active-row/
Share on other sites

Hello madhatter301,

 

You can select the desired row using the sql query posted by AndyB.

 

For updation:

 

To set the row to 'n' , you have to write two sql query:

 

1.  SELECT id from test WHERE `active` = 'y'

retrieve id_from from above statement

 

2  UPDATE `test` SET `active` = 'n' WHERE id=id_from

 

 

Regards

Aniesh Joseph

Link to comment
https://forums.phpfreaks.com/topic/42101-solved-active-row/#findComment-204226
Share on other sites

Well in that case I would set the active field to be an int(1) and use 0 for not active and 1 for active. The enum would just be a waste of processing time.

 

If you want when you pull it out of the DB you can (I know this works in Oracle but not sure about MySQL) do this

 

SELECT DECODE(active, 0, 'n', 1, 'y') FROM table ...

 

 

--FrosT

Link to comment
https://forums.phpfreaks.com/topic/42101-solved-active-row/#findComment-204465
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.