RagingEagle Posted February 23, 2007 Share Posted February 23, 2007 Hi, I'm having a problem incrementing a value and putting it into an Update statement, my code is as follows: $CurrentRank = 1; mysql_query("UPDATE The_Table SET Rank_Today = $CurrentRank"); $CurrentRank++; What I want it to do is place the incremented number by $CurrentRank++; into Rank_Today, but it doesn't work and instead it counts every row in the table and puts that number in every Rank_Today column. Anybody have any idea why I'm experiencing what I am? I've tried putting echo $CurrentRank; and it outputs the correct number to the page itself, but it doesn't send the right value to the database (as I said it sends the total counted number to the database, so if there are 30 rows it would place the number 30 in every Rank_Today column instead of going 1-30). Any help would be greatly appreciated. Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/39762-php-mysql-update-incremented-value/ Share on other sites More sharing options...
dustinnoe Posted February 23, 2007 Share Posted February 23, 2007 Try something like this <?php mysql_query("UPDATE The_Table SET Rank_Today+1"); ?> Quote Link to comment https://forums.phpfreaks.com/topic/39762-php-mysql-update-incremented-value/#findComment-192023 Share on other sites More sharing options...
RagingEagle Posted February 23, 2007 Author Share Posted February 23, 2007 Try something like this <?php mysql_query("UPDATE The_Table SET Rank_Today+1"); ?> I've tried that and I get the same result Quote Link to comment https://forums.phpfreaks.com/topic/39762-php-mysql-update-incremented-value/#findComment-192028 Share on other sites More sharing options...
dustinnoe Posted February 23, 2007 Share Posted February 23, 2007 Are you trying to insert another row? Because if so. <?php $query = "INSERT INTO The_Table (Rank_Today) VALUES((SELECT Rank_Today FROM The_Table ORDER BY Rank_Today DESC LIMIT 1)+1)"; ?> Something along those line might do the trick for you. Quote Link to comment https://forums.phpfreaks.com/topic/39762-php-mysql-update-incremented-value/#findComment-192285 Share on other sites More sharing options...
RagingEagle Posted February 23, 2007 Author Share Posted February 23, 2007 No, I'm not trying to insert a new row. I'm trying to update exsisting rows which daily will have a different rank value, so if there are 30 rows I'd like the top row to be rated 1 all the way through to the last row which would be 30. Quote Link to comment https://forums.phpfreaks.com/topic/39762-php-mysql-update-incremented-value/#findComment-192500 Share on other sites More sharing options...
fenway Posted February 26, 2007 Share Posted February 26, 2007 How are you ranking them? And why would you want to store this? Quote Link to comment https://forums.phpfreaks.com/topic/39762-php-mysql-update-incremented-value/#findComment-194438 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.