kmark Posted July 23, 2008 Share Posted July 23, 2008 Hi, I'm wondering if there is a way that I can increment all the values in a specific field by one by just using a single query. So the original records are: Name Number Mark 3 Kevin 10 and i want... Name Number Mark 4 Kevin 11 Quote Link to comment https://forums.phpfreaks.com/topic/116200-solved-increment-all-records-by-1/ Share on other sites More sharing options...
craygo Posted July 23, 2008 Share Posted July 23, 2008 <?php $sql = "UPDATE `tablename` SET `Number` = `Number`+1"; mysql_query($sql) or die(mysql_error()); ?> Ray Quote Link to comment https://forums.phpfreaks.com/topic/116200-solved-increment-all-records-by-1/#findComment-597538 Share on other sites More sharing options...
jonsjava Posted July 23, 2008 Share Posted July 23, 2008 <?php $sql = "UPDATE `tablename` SET `Number` = `Number`+1"; mysql_query($sql) or die(mysql_error()); ?> Ray curiosity got the best of me. I've never needed to run something like that myself, so my question for you is this: does it start at the bottom (the higest number), and work its way up? If not, that may pose problems for unique sets. If he is updating `Number` where id =1, and it becomes 2, and there is already one numbered 2.... Quote Link to comment https://forums.phpfreaks.com/topic/116200-solved-increment-all-records-by-1/#findComment-597555 Share on other sites More sharing options...
craygo Posted July 23, 2008 Share Posted July 23, 2008 LOL I don't ask how his data is setup, just answer the question. I know the potential problems with something like this, but I just help give the answer. Ray Quote Link to comment https://forums.phpfreaks.com/topic/116200-solved-increment-all-records-by-1/#findComment-597557 Share on other sites More sharing options...
kmark Posted July 23, 2008 Author Share Posted July 23, 2008 Its not an id field, its just if I number employee levels and I want to add one at the top it pushes everything down one. Works great by the way if I get rid of the quotes. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/116200-solved-increment-all-records-by-1/#findComment-597575 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.