找回密码
 免费注册

php获取数据库显示新闻内容案例附代码

[复制链接]
发表于 2022-11-30 14:29:00 | 显示全部楼层 |阅读模式
php获取数据库显示新闻内容案例附代码

步骤:
1、连接数据库
2、获取数据
3、遍历循环数据
代码如下:

  1. <style type="text/css">
  2.         table{
  3.                 width:780px;
  4.                 border:solid 1px #000;
  5.                 margin:auto;
  6.         }
  7.         th,td{
  8.                 border:solid 1px #000;
  9.         }
  10. </style>
  11. <body>
  12. <?php
  13. //1、连接数据库
  14. require './inc/conn.php';
  15. //2、获取数据
  16. $rs=mysqli_query($link,'select * from news order by id desc');        //返回结果集对象
  17. $list=mysqli_fetch_all($rs,MYSQLI_ASSOC);                //将结果匹配成关联数组
  18. ?>
  19. <table>
  20.         <tr>
  21.                 <th>编号</th> <th>标题</th> <th>内容</th> <th>时间</th> <th>修改</th> <th>删除</th>
  22.         <!--3、循环显示数据-->
  23.                 <?php foreach($list as $rows):?>
  24.                 <tr>
  25.                         <td><?php echo $rows['id']?></td>
  26.                         <td><?php echo $rows['title']?></td>
  27.                         <td><?php echo $rows['content']?></td>
  28.                         <td><?php echo date('Y-m-d H:i:s',$rows['createtime'])?></td>
  29.                         <td><input type="button" value="修改" onclick=""></td>
  30.                         <td><input type="button" value="删除" onclick=""></td>
  31.                 </tr>
  32.                 <?php endforeach;?>
  33.         </tr>
  34. </table>
  35. </body>
复制代码
运行结果

代码运行结果.jpg

QQ|Archiver|小黑屋|网站地图|深圳市金黑网络技术有限公司 ( 粤ICP备2021124338号|粤公网安备 44030702003689号 )

GMT+8, 2026-8-8 17:13 , Processed in 0.056278 second(s), 25 queries .

Powered by Discuz! X3.5

© 2001-2026 Discuz! Team.

快速回复 返回顶部 返回列表