Jump to content

Archived

This topic is now archived and is closed to further replies.

master82

Field Updates

Recommended Posts

Here is what i currently have to update my users days old - it will be part of a cron that is run at midnight.

[code]include_once("connectionfile.php");
mysql_query("UPDATE users SET daysold=daysold+1",$connect);[/code]

Now if I was to run this would it go through each row in the users table and add 1 to the field named 'daysold' or will it do the thing I really dont want and make everyones 'daysold' the same.

If the second, can anyone add to my code to make the calculation for each row?

Share this post


Link to post
Share on other sites
I think it'll go through each user in the database and update the daysold field.

Share this post


Link to post
Share on other sites
Thats what I thought might happen.

Any idea how I would do it for each row in the users table?

Share this post


Link to post
Share on other sites
[code]$query = mysql_query( "select * from users" );

while( $row = mysql_fetch_array( $query ) )
{
mysql_query( "update users set daysold = daysold+1 where id = '$row[id]'" );
}[/code]


Would this work?

Share this post


Link to post
Share on other sites

×

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.