用mysql开发PHP新闻系统?
我正在尝试用php制作一个新闻系统。 DB结构如下所示用mysql开发PHP新闻系统?,php,mysql,Php,Mysql,我正在尝试用php制作一个新闻系统。 DB结构如下所示 "title" "author" "content" <?php include ('config2.php'); $result = mysql_query("select * from news"); while($row = mysql_fetch_array($result)) { $title = $row['title']; $author = $row['author']; $content = $row
"title" "author" "content"
<?php
include ('config2.php');
$result = mysql_query("select * from news");
while($row = mysql_fetch_array($result)) {
$title = $row['title'];
$author = $row['author'];
$content = $row['content'];
}
echo"<div class=\"post\">
<h2 class=\"title\"><font color=\'#1e1e1e\' href=\"#\">$title</font></h2>
<p class=\"meta\">Today <a href=\"#\">$author</a></p>
<p>$content</p>
</ul>
</div>"
?>
PHP脚本如下所示
"title" "author" "content"
<?php
include ('config2.php');
$result = mysql_query("select * from news");
while($row = mysql_fetch_array($result)) {
$title = $row['title'];
$author = $row['author'];
$content = $row['content'];
}
echo"<div class=\"post\">
<h2 class=\"title\"><font color=\'#1e1e1e\' href=\"#\">$title</font></h2>
<p class=\"meta\">Today <a href=\"#\">$author</a></p>
<p>$content</p>
</ul>
</div>"
?>
我想做的是:每次我在数据库中插入新行时,我都希望新的行显示在页面上,而现在当我添加新行时,它只是编辑以前的新行。
有什么想法吗?把
echo
语句放在while
循环内。你在echo
while循环外。将其修改为以下内容:
while($row = mysql_fetch_array($result)) {
$title = $row['title'];
$author = $row['author'];
$content = $row['content'];
echo"<div class=\"post\">
<h2 class=\"title\"><font color=\'#1e1e1e\' href=\"#\">$title</font></h2>
<p class=\"meta\">Today <a href=\"#\">$author</a></p>
<p>$content</p>
</ul>
</div>";
}
while($row=mysql\u fetch\u array($result)){
$title=$row['title'];
$author=$row['author'];
$content=$row['content'];
回声“
$title
今天
$content
";
}
您正在使用的mysql.*
函数已被弃用,并将从未来的PHP版本中删除。不要用它们编写新代码,而是使用myqsli.*
或PDO。