Message board d...LOGIN

Message board display page developed by PHP

If we want the messages we publish to be displayed together with the home page, we need to use a mixture of our HTML and PHP languages. See the code below

We have successfully published the message from the HTML page, indicating The data has been successfully stored in the database. We only need to read the data from the database. The code is as follows

<?php
session_start();
header( "content-type:text/html;charset=utf-8");
$conn=mysqli_connect("localhost","root","root","Ressage");
mysqli_set_charset($conn, 'utf8'); //Set character set
$sql= "select * from ressage_user;
$result=mysqli_query($conn,$sql);

?>

The above two lines of code allow us to query the data from the database.

The difficult part is how to display it in the specified format on the html page. See below Code

<p>
            <?
            if($result==null){
                echo"暂时没有留言";
            }  ?>
        </p>
        <?php
        while($row=mysqli_fetch_array($result)){
            ?>
            <table border="1" cellspacing="0">
        <tr>
            <td>姓名:<?php  echo $row['name']?></td>  
            <td style="text-align: center">留言时间:<?php echo $row['ressage_time']?></td>
            <td><a href="ressage_delete.php?id=<?php echo $row['id']?>" >删除</a> </td>
        </tr>
        <tr>
            <td colspan="3">你的留言:<?php echo $row['content']?></td>
        </tr>
            </table>
<?php
             }?>

The above code is a mix of our HTML and PHP. We first read the data in our database in the form of an array, and then we take the corresponding fields and loop them out. Combining the codes can read and display our data, but we also need to put these codes together with our home page code, so these codes need further combination, see the next chapter



Next Section
<!doctype html> <html> <head> <meta charset="utf-8"> <title>PHP中文网</title> </head> <body> <h2>PHP留言板展示页面</h2> </body> </html>
submitReset Code
ChapterCourseware