Jump to content

PHP & MYSQL Update Incremented Value


RagingEagle

Recommended Posts

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!

Link to comment
https://forums.phpfreaks.com/topic/39762-php-mysql-update-incremented-value/
Share on other sites

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.

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.