我想顯示帶有日期郵件的新聞標題旁邊。出於某種原因,每個人的日期都是一樣的;我沒有在同一天發佈所有這些數據,因爲每個數據庫中的日期都不相同。爲什麼我不能爲我的頭顯示不同的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();
?>
'E_TOO_MUCH_TABS' – HamZa
你什麼時候設置變量$ d? – Preexo
$ d = strtotime($ row ['created']); \t \t \t \t \t \t \t $ id = $ row ['id']; $ date = date('jS F Y',$ d); – Fresz