I’d like to update mySql row with a number which is represents a status. For example :
1 = New
2 = Old
By default, when a new data has been added to mySql. The status is set to “1” automatically. And this is the point. I’d like to update it automatically to “2” when the day is more than a week (7 days). Here is the codes:
<?php
$_toDay=date("Y-m-d");
.....
while($rec_gid=mysql_fetch_array($result_gid)){
$gid=$rec_gid['goods_id'];
$dateDB=$rec_gid['goods_date'];
$_diff = abs(strtotime($_toDay) - strtotime($dateDB));
$_years = floor($_diff / (365*60*60*24));
$_mon = floor(($_diff - $_years * 365*60*60*24) / (30*60*60*24));
$_days = floor(($_diff - $_years * 365*60*60*24 - $_mon*30*60*60*24)/ (60*60*24));
if($_days>7){//if older than a week then change status
$sql_updStts="update goods_db set stts='2' where id='$_gid'";
$result_updStts=mysql_db_query($dbname,$sql_updStts);
}//close while
?>
I’ve tried this script but the outcome is not as I expected. Even the $_days is more than a week. mySql is not update. I don’t know why. Any idea?
Try