I have a website that allows people to post ads. Ads remain active for 30 days. In their control panel they can manage their ads, i.e., Edit, Delete, Renew, etc.
In this case I’m working with the “Renew” feature. I want to show how many days they have left before their ad becomes inactive.
When they submit an ad the date is recorded in the database using MySQL’s DATE function. (I’m not interested in the “time”, just the date). Here’s how I query the database and the code to do the above:
[code=php]$query = “SELECT DATE_FORMAT(submitted, ‘%m/%d/%y’) AS date FROM ads WHERE id=’$id'”;
$result = mysql_query($query) or trigger_error(“Query: $queryn<br>MySQL Error: ” . mysql_error());
while ($row = mysql_fetch_array($result, MYSQL_ASSOC))
{
$date = stripslashes($row[‘date’]);
}
$originaldate = $date; //any properly formated date
$ageindays = number_format(floor((date(“U”)-strtotime($originaldate))/86400),0);
//print $ageindays . ” days”;
$torenew = 30 – $ageindays;
echo ”
Date Posted: $date
<br><br>
Ads remain active for 30 days.
<br><br>
“;
if ($torenew <= ‘0’)
{
echo “<span style=’color:red’><strong>Ad Expired</strong></span>”;
}
else
{
echo “You will need to renew this ad in <span style=’color:red’><strong>$torenew</strong></span> days.”;
}
OK, it works. But it triggers this error message:
[code=php]date(): It is not safe to rely on the system’s timezone settings. Please use the date.timezone setting, the TZ environment variable or the date_default_timezone_set() function. In case you used any of those methods and you are still getting this warning, you most likely misspelled the timezone identifier. We selected ‘America/New_York’ for ‘EST/-5.0/no DST’ instead
I tried using this:
[code=php]$ageindays = number_format(floor(date_default_timezone_set(‘America/Indianapolis’)-strtotime($originaldate))/86400),0);
But it gave the error:
[code=php]Parse error: syntax error, unexpected ‘,’ in /hsphere/local/home/davida261/elmorons.com/members/manage_ad.php on line 76
That’s the comma in the above just behind the – 86400)
How can I correct this?
Thanks
Alan P