steve_683 Posted April 22, 2009 Share Posted April 22, 2009 This is quite a novice question, and hopefully one with an easy answer. I want to go through a MySQL table on my server and change value=`0` to value=`3` everywhere where attributeid==`2` (and value==`0`). Here`s what the table looks like: | attributeid | userid | value | ----------------------------- | 1 | 1 | 1 | | 2 | 1 | 0 | | 3 | 1 | 45 | | 1 | 2 | 1 | | 2 | 2 | 4 | ...and so on So I guess I run the following code: $newvalue = 3; mysql_query("UPDATE name_of_table SET value='$newvalue' WHERE (value=='0' AND attributeid=='2')"); Is this going to work, or am I potentially going to screw-up something? I'm a very novice programmer, and I'm very worried I'm going to make some kind of serious mistake. Quote Link to comment https://forums.phpfreaks.com/topic/155233-go-through-a-table-in-the-database-and-chance-all-value0-to-value3/ Share on other sites More sharing options...
kickstart Posted April 22, 2009 Share Posted April 22, 2009 Hi Pretty much, although SQL does not require double == when checking a value (single = will be fine). All the best Keith Quote Link to comment https://forums.phpfreaks.com/topic/155233-go-through-a-table-in-the-database-and-chance-all-value0-to-value3/#findComment-816689 Share on other sites More sharing options...
PFMaBiSmAd Posted April 22, 2009 Share Posted April 22, 2009 Testing code involves actually trying something and seeing if the results are what you expect, this is why you run tests on a development system where the data either does not matter or you have a backup of it that you can easily restore if something goes wrong. Edit: following is basically the same as posted above - The only thing you need to change is the double == signs should be single = In SQL a comparison is only one = sign. Quote Link to comment https://forums.phpfreaks.com/topic/155233-go-through-a-table-in-the-database-and-chance-all-value0-to-value3/#findComment-816694 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.