List display
After adding data to the database, we then want to display the data in the database on our front page. This is our display function.
First of all, if we want to display the data in the database, we need to connect to our database. As mentioned before, there will be many places where the database connection code is used. It will be very troublesome to write it every time. , we re-create a file, write the connection database into it, and then call it.
<?php session_start(); header("content-type:text/html;charset=utf-8"); require 'config.php'; ?>
Name the new file config.php, just quote it directly
The next step is to query the data from the database and display the found data on the front-end page .
<?php $SQL = "select * from list";//设置查询指令 $result=mysqli_query($link,$SQL);//执行查询 ?>
Find the data from the list data table, and then display it on the front-end page. Let's take a look at the front-end file.
<?php while($row=mysqli_fetch_assoc($result)) ?> <tr> <td style="text-align:left; padding-left:20px;"><input type="checkbox" name="id" value="" /><?php echo $row['id'];?></td> <td><span><?php echo $row['author'];?></span></td> <td width="10%"><img src="<?php echo $row['image'];?>" alt="" width="70" height="50" /></td> <td width="30%"><span><?php echo $row['content'];?></span></td> <td><span>首页</span></td> <td><span><?php echo $cat_array[$row['cid']];?></span></td> <td><span>2016-07-01</span></td> <td><div class="button-group"> <a class="button border-main" href="edit.php?id=<?php echo $row['id']?>"> <span class="icon-edit"></span> 修改</a> <a class="button border-red" href="del.php?idD=<?php echo $row['id']?>" onclick="return del(1,1,1)"> <span class="icon-trash-o"></span>删除</a> </div> </td> </tr> <?php endwhile;?>
We only need to display the queried data in a loop on the front-end page.
We assign the queried value to $row in the form of an array and loop it out through the while loop. Loop out in the corresponding place on the front-end page in the form of <?php echo $row['']?>. In this way, our display page is completed.
We will talk about paging and keyword search in the next section.