PHP 개발 뉴스 릴리스 시스템 뉴스 목록 페이지
뉴스 목록 페이지 new_list.php 파일을 만듭니다
우리가 게시하는 모든 뉴스가 이 페이지에 표시됩니다
먼저 데이터베이스에서 데이터를 찾으세요. 코드는 다음과 같습니다. follow
<?php
header("content-type:text/html;charset=utf8");
$conn=mysqli_connect("localhost","root","root","News");
mysqli_set_charset($conn,'utf8'); //设定字符集
$sql="select * from new";
$que=mysqli_query($conn,$sql);
?>데이터를 HTML 페이지에 표시하려면 HTML과 PHP 언어를 혼합하여 사용해야 합니다.
코드는 다음과 같습니다
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP中文网</title>
<style>
table{
margin-top: 10px;
}
</style>
</head>
<body>
<a href="new.html">返回发布新闻</a>
<table border="1" cellspacing="0" width=360 >
<tr>
<th>编号</th>
<th>文章标题</th>
<th>文章内容</th>
<th>编辑文章</th>
<th>发布时间</th>
</tr>
<?php
while($row=mysqli_fetch_array($que)){
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['title']?></td>
<td><?php echo $row['content']?></td>
<td>
<a href="new_ed.php?id=<?php echo $row['id']?>">修改</a>
<a href="new_del.php?id=<?php echo $row['id']?>">删除</a>
</td>
<td><?php echo $row['cre_time']?></td>
<?php }
?>
</tr>
</table>
</body>
</html>new_list.php new_list.php 파일의 전체 코드는 다음과 같습니다
<?php
header("content-type:text/html;charset=utf8");
$conn=mysqli_connect("localhost","root","root","News");
mysqli_set_charset($conn,'utf8'); //设定字符集
$sql="select * from new";
$que=mysqli_query($conn,$sql);
?>
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>PHP中文网</title>
<style>
table{
margin-top: 10px;
}
</style>
</head>
<body>
<a href="new.html">返回发布新闻</a>
<table border="1" cellspacing="0" width=360 >
<tr>
<th>编号</th>
<th>文章标题</th>
<th>文章内容</th>
<th>编辑文章</th>
<th>发布时间</th>
</tr>
<?php
while($row=mysqli_fetch_array($que)){
?>
<tr>
<td><?php echo $row['id'];?></td>
<td><?php echo $row['title']?></td>
<td><?php echo $row['content']?></td>
<td>
<a href="new_ed.php?id=<?php echo $row['id']?>">修改</a>
<a href="new_del.php?id=<?php echo $row['id']?>">删除</a>
</td>
<td><?php echo $row['cre_time']?></td>
<?php }
?>
</tr>
</table>
</body>
</html>위 코드는 우리가 게시하는 모든 뉴스를 HTML 페이지에 표 형태로 표시할 수 있습니다


