2013-07-02 66 views
0

我想顯示帶有日期郵件的新聞標題旁邊。出於某種原因,每個人的日期都是一樣的;我沒有在同一天發佈所有這些數據,因爲每個數據庫中的日期都不相同。爲什麼我不能爲我的頭顯示不同的PHP日期值?

這裏是我的代碼:高達哪裏,你做你的查詢

<?php 
// Connect to the database 
$dbLink = new mysqli('localhost', 'root', 'root', 'olearyinternational'); 
if(mysqli_connect_errno()) { 
    die("MySQL connection failed: ". mysqli_connect_error()); 
} 
// Query for a list of all existing files 
$sql = 'SELECT * FROM `posts` order by created desc limit 8'; 
$result = $dbLink->query($sql); 
$date = date('jS F Y', $d); 
// Check if it was successfull 
if($result) { 
    // Make sure there are some files in there 
    if($result->num_rows == 0) { 
     echo '<p>There are no files in the database</p>'; 
    } 
    else { 
     while($row = $result->fetch_assoc()) { 
?> 
      <li class="good-font"><a href="news.php"><?php echo $row['title'] ?><span id = "post_date"><?php echo $date; ?></a></li> 
<?php 
     } 
     // Close table 
     echo '</table>'; 
     // Free the result 
     $result->free(); 
    } 
} 
else { 
    echo 'Error! SQL query failed:'; 
    echo "<pre>{$dbLink->error}</pre>"; 
} 
// Close the mysql connection 
$dbLink->close(); 
?> 
+5

'E_TOO_MUCH_TABS' – HamZa

+0

你什麼時候設置變量$ d? – Preexo

+0

$ d = strtotime($ row ['created']); \t \t \t \t \t \t \t $ id = $ row ['id']; $ date = date('jS F Y',$ d); – Fresz

回答

2

你$日期被初始化一次。您需要在每行中回顯postdate而不是$ date。檢查你的模式,它可能會像$ row ['date']或$ row ['post_date']。如果您需要更改格式,請在while循環內執行。

+0

謝謝,我只是把這個$ d = strtotime($ row ['created']); \t \t \t \t \t \t \t \t \t \t $ ID = $行[ 'ID']; \t \t \t $ date = date('jS F Y',$ d);進入while循環和它的工作。 – Fresz