我有多个文章存储在我的数据库中,我想要显示。但是,只有最近的文章才显示在页面上,而不是全部。任何帮助显示所有文章将不胜感激。为什么我的所有记录都没有显示?
<div class="column-center">
<?php
include 'includes/connect.php';
$select_news = "select * FROM news";
$run_news = mysql_query($select_news);
while ($row_news=mysql_fetch_array($run_news)){
$article_id = $row_news['article_id'];
$article_title = $row_news['article_title'];
$article_date = $row_news['article_date'];
$article_author = $row_news['article_author'];
$article_keywords = $row_news['article_keywords'];
$article_content = $row_news['article_content'];
$article_image = $row_news['article_image'];
}
echo "
<a href='details.php?article=$article_id'>$article_title</a>
<div>$article_content <a href='article.php?article=$article_id'>Read More</a></div><br />
<img src='images/$article_image' width='100' height='100'/>
";
?>
</div>
请[停止使用'mysql_ *'函数](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 [这些扩展](http://php.net/manual/en/migration70.removed-exts-sapis.php)已在PHP 7中删除。了解[编写](http://en.wikipedia.org/ wiki/Prepared_statement)语句[PDO](http://php.net/manual/en/pdo.prepared-statements.php)和[MySQLi](http://php.net/manual/en/mysqli.quickstart .prepared-statements.php)并考虑使用PDO,[这真的很简单](http://jayblanchard.net/demystifying_php_pdo.html)。 –
因为当你在'while'循环中设置这些变量时,你是__overwriting__你为前一个记录设置的值 –
将echo()上移到循环中,就在结束括号之前。 :d – HoratioCain