Jump to content


Photo

Field Updates


  • Please log in to reply
4 replies to this topic

#1 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 04 September 2006 - 05:37 PM

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

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

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?

#2 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 04 September 2006 - 05:43 PM

I think it'll go through each user in the database and update the daysold field.

#3 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 04 September 2006 - 05:44 PM

Thats what I thought might happen.

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

#4 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 04 September 2006 - 05:48 PM

$query = mysql_query( "select * from users" );

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


Would this work?

#5 master82

master82
  • Members
  • PipPipPip
  • Advanced Member
  • 182 posts

Posted 04 September 2006 - 05:50 PM

oh think i misread that 1 lol




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users