php开发留言板之查看留言
创建文件list.php
<!DOCTYPE html>
 <html lang="utf-8">
 <head>
    <?php
 include ("conn.php");
 ?> 
  <link href="css.css" rel="stylesheet" type="text/css">
 </head>
 
 
 <table width=500 border="0" align="center" cellpadding="5" cellspacing="1" bgcolor="#add3ef" >
     <?php
     $sql="select * from message order by id desc";
     $query=mysql_query($sql);
     while($row=mysql_fetch_array($query)){  ?>
 
         <tr bgcolor="#eff3ff">
             <td>标题: <?php echo $row['title'];?> <font color="red">用户: <?php echo $row['user'];?> </td>
         </tr>
         <tr bgColor="#ffffff">
             <td>发表内容:<?php echo $row['content'];?></td>
         </tr>
         <tr bgColor="#ffffff">
             <td><div align="right">时间:<?php echo $row['lastdate'];?></td>
         </tr>
     <?php } ?>
     <tr bgcolor="#f0fff0">
         <td><div align="right"><a href="add.html">返回留言</a> </td>
     </tr>
 </table>
 </html>引入css样式文件和conn数据库文件
<?php
    $sql="select * from message order by id desc";
    $query=mysql_query($sql);
    while($row=mysql_fetch_array($query)){ 
    } ?>连接message数据库进行倒叙排序
mysql_query进行查询
mysql_fetch_array()-获取和显示数据格式
然后把所需的数据分别写出来
 
写到这留言板基本已经成型了,后面可以给留言板添加删除功能,让其更为完善。
本章重点:
- 在html语句中插入php语句,HTML和PHP的混编。 
- 使用倒叙的方式显示数据,最新的放在最前面,更能符合人们使用的习惯。 
- mysql_query进行查询和mysql_fetch_array()-获取和显示数据格式这两个方法的使用。 
 
			 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
									 
								 
								

 
  
             
        
好人
看了好久看不懂时间是什么时间加进数据库的
5年前 添加回复 0