...

View Full Version : updating multiple rows



ido3dfx
07-14-2008, 05:27 PM
I have a user table in which each record has an id and a date field (among otheres)
the id is int and the date field is date formatted 0000-00-00

I want a query to run any time this page is viewed (this way no form is needed) that it would update the date field in every record when compared to the current date.



$now = date ('Y-m-d');


$query = "SELECT * FROM `t1m_users` WHERE `active` ='1' ";
$result = mysql_query($query) or die(mysql_error());

$i = 0;
while $row = mysql_fetch_array($result));{
$id = $row['id'];
$expired = $row['join_expd'];

++$i;
}




I know I need to loop and check each users 'join_expd' field and compare it to $now then if it is greater (meaning now = 2008-07-15 and join_expd = 2008-07-14 ) I want to set the active fields to '0'.

this will set all users accounts who have expired to inactive. I dont want to delete them.

thanks in advance for the help


best regards,

MM :)

abduraooft
07-14-2008, 05:34 PM
Check the syntax of while loop from http://in.php.net/while
Have you got any error from your current code?

fl00d
07-14-2008, 05:39 PM
Can't he just use one query with no limit instead of multiple queries in a loop?


$sql = "UPDATE `tlm_users` SET `active`='0' WHERE `join_expd` < CURDATE()";
$query = mysql_query($sql);


Untested but I think it would work.

ido3dfx
07-14-2008, 07:32 PM
Can't he just use one query with no limit instead of multiple queries in a loop?


$sql = "UPDATE `tlm_users` SET `active`='0' WHERE `join_expd` < CURDATE()";
$query = mysql_query($sql);


Untested but I think it would work.

how would it know what record/row to update ? with that query I am prettty sure it would only do the last record with the expired date.

ohgod
07-14-2008, 07:36 PM
no... it would change any rows meeting the specified conditions

ido3dfx
07-14-2008, 07:42 PM
no... it would change any rows meeting the specified conditions

you know....BY GEORGE I think you've got it!!


I'll give it a run.;)

ido3dfx
07-14-2008, 08:01 PM
You Da Man !!!



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum