View messages on php development message board


Create filelist.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>

Introduce css style files and conn database files

<?php
    $sql="select * from message order by id desc";
    $query=mysql_query($sql);
    while($row=mysql_fetch_array($query)){ 
    } ?>

Connect the message database for flashback sorting

mysql_queryQuery

mysql_fetch_array()-Get and display data format
Then write out the required data separately

As of writing, this message board has basically taken shape. You can add a delete function to the message board later to make it more complete.


Key points of this chapter:

  1. Insert php statements into html statements, a mixture of HTML and PHP.

  2. Use flashback to display data, with the latest one at the front, which is more in line with people's usage habits.

  3. Mysql_query is used to query and mysql_fetch_array()-get and display data format.

Continuing Learning
||
<!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=" ">返回留言</ a> </td> </tr> </table> </html>
submitReset Code