简体   繁体   English

PHP新闻系统与MySQL?

[英]PHP news system with mysql?

I am trying to make a news sytem in php. 我正在尝试在php中创建一个新闻系统。 The DB structure looks like this 数据库结构如下所示

"title"  "author"  "content"

And the PHP script looks like this PHP脚本如下所示

<?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>"
 ?>

What I want to do is : Each time I insert a new row in my db, I want the new to be displayed on the page, and right now when I add a new row it just edit the previous new. 我想要做的是:每次在数据库中插入新行时,我都希望该新行显示在页面上,现在,当我添加新行时,只需编辑先前的新行即可。 Any idea? 任何想法?

echo语句放入 while循环中。

You're echo ing outside the while loop. echo荷兰国际集团外while循环。 Modify it to the following: 修改为以下内容:

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>";
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM