php開發(fā)留言板之查看留言
創(chuàng)建文件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>標(biāo)題: <?php echo $row['title'];?> <font color="red">用戶: <?php echo $row['user'];?> </td> </tr> <tr bgColor="#ffffff"> <td>發(fā)表內(nèi)容:<?php echo $row['content'];?></td> </tr> <tr bgColor="#ffffff"> <td><div align="right">時(shí)間:<?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數(shù)據(jù)庫文件
<?php $sql="select * from message order by id desc"; $query=mysql_query($sql); while($row=mysql_fetch_array($query)){ } ?>
連接message數(shù)據(jù)庫進(jìn)行倒敘排序
mysql_query進(jìn)行查詢
mysql_fetch_array()-獲取和顯示數(shù)據(jù)格式
然后把所需的數(shù)據(jù)分別寫出來
寫到這留言板基本已經(jīng)成型了,后面可以給留言板添加刪除功能,讓其更為完善。
本章重點(diǎn):
在html語句中插入php語句,HTML和PHP的混編。
使用倒敘的方式顯示數(shù)據(jù),最新的放在最前面,更能符合人們使用的習(xí)慣。
mysql_query進(jìn)行查詢和mysql_fetch_array()-獲取和顯示數(shù)據(jù)格式這兩個(gè)方法的使用。