2012-07-30 25 views
2

我想成爲廣告經理。當廣告達到其到期日期時,它將變爲非激活狀態。但是,當我試圖製作並嘗試它時,即使尚未達到其到期日期,所有廣告也會變爲無效。某個日期後自動失效

這裏是我的代碼:

$query_banner = mysql_query("SELECT * FROM ad_tbl ORDER BY ID DESC LIMIT $from,$max_show") or die(mysql_error()); 
while($show=mysql_fetch_array($query_banner)) 
{ 
    $no++; 
    if(($no%2)==0) 
    $color = '#f2f2f2'; 
    else 
    $color = '#f9f9f9'; 

    $expired_date = $show['expiry_date']; 
    $today_date = date("m/d/Y"); 

    $expired = strtotime($expiry_date); 
    $today = strtotime($today_date); 

    if($expired > $today) 
    { 
    $valid = "yes"; 
    } 
    else 
    { 
    $valid = "no"; 
    $query_expired = mysql_query("UPDATE ad_tbl SET status='Non-Active' WHERE expiry_date <= $today") or die(mysql_error());  
    } 
} 
+2

'strtotime()'返回一個整數值,而MySQL通常以'YYYY-mm-dd'格式存儲日期。 – 2012-07-30 00:26:51

+1

只是一個提示,它會更好地優化狀態作爲一個位,整數或枚舉字段(取決於狀態的數量)比文本字段。 – 2012-07-30 00:28:59

+0

好的謝謝:)我會改變它......謝謝你的提示:D – messerchainey 2012-07-30 00:38:06

回答

0

嘗試:

$expiredDateTime = new DateTime($expiry_date); 
    $expired = $expiredDateTime->format('U'); 
    $today = date('U'); // This will default give you timestamp for "now", saving you a step 

如果這樣的作品,然後我怕你m/d/y格式可能是問題的根源。要檢查你應該回應你的strtotime值,並將其粘貼到轉換器,看看它說什麼。