Jump to content

updating mysql date field


mahalleday

Recommended Posts

I am creating a classifieds application useing php and mysql.  I when an ad is created the user can select the duration they want their ad to run.  In the database an ad_start and ad_end is created.

The ad_end feild is created like this ADDDATE(NOW(), INTERVAL '$ad_durr' day)

 

I then use the following code at the top of the file to display ads to check and see if any ads should be expired and if so set expired = 1

 

<?php
  $sql = "SELECT ad_id FROM ".TABLE_PREFIX."mod_ad_baker_ads WHERE ad_end <= CURDATE()";
  $query = $database->query($sql) OR die($sql);
  while($exipred = $query->fetchRow()) {
    $sql = "UPDATE ".TABLE_PREFIX."mod_ad_baker_ads SET expired = 1 WHERE ad_id = ".$expired['ad_id'];
    $query = $database->query($sql) OR die($sql);
}
?>

 

This is the code I have wrtten when a user wants to renew their ad

 

<?php
    $sql = 'UPDATE '.TABLE_PREFIX.'mod_ad_baker_ads SET
            expired = '.$value',
            ad_end = ADDDATE('.$start.', INTERVAL '.$duration.'DAY),
            WHERE ad_id = '.$id;

    $query = $database->query($sql);
?>

 

The ads expire fine but I can't get the renew script to change the ad_end feild when the ads is renewed.

Link to comment
https://forums.phpfreaks.com/topic/176248-updating-mysql-date-field/
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.