timmah1 Posted December 30, 2006 Share Posted December 30, 2006 This might be hard to explain, but hopefully someone will be able to understand this.I have a field in my database named 'main', that field either has a yes or no in it, with only 1 item can have yes in, the rest MUST have no.The items in this will constantly change, with either more or less items.When I update the field, how can I change every item in the database at the same time?Meaning, when one is yes, the rest automatically change to no?This goes back to my update thread, for a better example, think of MySpace, when you change your default picture.Thanks again in advance Link to comment https://forums.phpfreaks.com/topic/32241-solved-update-all-fields-in-database/ Share on other sites More sharing options...
trq Posted December 30, 2006 Share Posted December 30, 2006 [quote]when one is yes, the rest automatically change to no?[/quote]You would be best of to do this with a trigger but I think only mysql 5> support them.You could simply do it this way though.[code]<?phpif (mysql_query("UPDATE tbl SET main = 'yes'")) { // update all to yes. if (mysql_query("UPDATE tbl SET main = 'no' WHERE id = 1")) { // update a particular row to no. echo "update success"; }}?>[/code] Link to comment https://forums.phpfreaks.com/topic/32241-solved-update-all-fields-in-database/#findComment-149633 Share on other sites More sharing options...
timmah1 Posted December 30, 2006 Author Share Posted December 30, 2006 Your a godsend!thank you so, so [b]much[/b]! Link to comment https://forums.phpfreaks.com/topic/32241-solved-update-all-fields-in-database/#findComment-149643 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.