2012-12-17 69 views
0

我寫一個PHP代碼由管理員設定一個截止日期,讓管理員通過輸入形式daedline日期,它會存儲在數據庫中,現在我想用這個最後期限,只要檢查用戶要訪問的網頁,如果截止日期過期的用戶無法訪問該網頁時,他會自動轉移到所謂的「closed.html」頁面上,如果沒有用戶可以訪問它..我已經試過這個代碼但它保持移動到closed.html頁面,即使日期尚未過期!想法請嗎?PHP - 截止日期查詢

<?php 
session_start(); 
$Load=$_SESSION['login_user']; 
$sql= "Select deadline from schedule_deliverables"; 
$deadline = mysql_query($sql); 
$todays_date = date("Y-m-d"); 

$today = strtotime($todays_date); 
$expiration_date = strtotime($deadline); 

if ($expiration_date > $today) { 
    echo "<meta http-equiv='refresh' content='1;URL=Check_file.php'>"; //user can access the page 
} else { 
    echo "<meta http-equiv='refresh' content='1;URL=closed.html'>"; //deadline is past user can't access 

} 


?> 
+0

而正是你建立你的數據庫連接?只是'mysql_query'不會削減它(也被棄用的方式,使用庫MySQLi或PDO來代替,看到的mysql_query [手動](http://php.net/mysql_query))。這是完整的代碼還是你遺漏了某些部分? – Oldskool

+0

請不要使用'mysql_ *'功能更多http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php/12860140#12860140 –

回答

1

您需要fetch_Array

$query = "Select deadline from schedule_deliverables"; 

$result = mysql_query($query) or die(mysql_error()); 


$row = mysql_fetch_array($result) or die(mysql_error()); 
$deadline = $row['deadline']; // and then you rest code with that if 
+0

+1這應該是正確的。我想補充的,加入'LIMIT 1'(MySQL的)或'TOP 1'(TSQL)限制查詢(或一個似是而非的where子句)真的只得到一個結果 – Najzero

+0

@Najzero吧:) – pregmatch