为什么不';我是否为标题显示不同的PHP日期值?
我正试图在新闻标题旁边显示邮资日期。由于某种原因,它们的日期都是相同的;我并没有在同一天发布所有的日志,因为数据库中的日期各不相同 这是我的密码:为什么不';我是否为标题显示不同的PHP日期值?,php,mysql,date,Php,Mysql,Date,我正试图在新闻标题旁边显示邮资日期。由于某种原因,它们的日期都是相同的;我并没有在同一天发布所有的日志,因为数据库中的日期各不相同 这是我的密码: <?php // Connect to the database $dbLink = new mysqli('localhost', 'root', 'root', 'olearyinternational'); if(mysqli_connect_errno()) { die("MySQL connection failed: ".
<?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();
?>
您的$date在您执行查询的地方初始化一次。您需要在每行中回显postdate,而不是$date。检查您的模式,它可能类似于$row['date']或$row['post_date']。如果需要更改格式,请在while循环中执行。何时设置变量$d?$d=strottime($row['created']);$id=$row['id']$日期=日期('jS F Y',$d)$日期=日期('jS F Y',$d);谢谢,我只是把这个$d=strottime($row['created']);$id=$row['id'];$date=日期($jS F Y',$d);进入while循环,它工作了。