What I'm trying to do is simple, yet for the life of me, I can't get it to work.
Basically:
1. I want to select data from a table, loop through the data with mysql_fetch_array, and use it to do some date calculation.
- Based on the result of the calculation, I want another column updated within the same table.
In other words, for each iteration of the loop, I'm carrying out another db query to update the same table. This query is not updating the table.
Note: $connection is correct in the actual php script.
Here is the code, and any help will be greatly appreciated.
$db = "mydb";
$query = "select lastEdit,id from agents ";
$result = @mysql_db_query($db,$query,$connection);
while ($myrow = mysql_fetch_array($result))
{
$id = $myrow["id"];
$lastEdit = strtotime ($myrow["lastEdit"]); // convert to seconds
$CURRENT_DATE = strtotime ("now"); // current time in seconds
$db = "mydb";
$sql = "update agents set ";
if(($CURRENT_DATE - $lastEdit)>86400) // 1 day
{
$sql .= "oneDay *=0 ";
}
$sql .= "where id='$id' limit 1";
$updtResult = mysql_db_query($db,$sql,$connection);
}