前端呈现
<?php foreach($pic as $p) {?>
<tr align="center">
<td><?php echo $p['id'];?></td>
<td><?php echo $p['picturename'];?></td>
<td><?php echo $p['picturetime'];?></td>
<td>
<a href="pic_edit.php?id=<?php echo $p['id'];?>" class="ui mini teal basic button">编辑</a>
<a href="pic_del.php?id=<?php echo $p['id'];?>" onclick="return confirm('确定要删除该照片吗?三思啊! 删了可就没了!')"
class="ui mini red basic button">删除</a>
</td>
</tr>
<?php }?>
PHP对数据库中的数据进行遍历,并取出给到前端
?
<?php
header('Content-type:text/html;charset=utf-8');
//连接认证
$link = mysqli_connect('localhost:3306','root','123456') or die('连接失败');
//设定字符集
mysqli_query($link,'set names utf8');
//选择数据库
mysqli_query($link,'use myblog');
//从数据表中取出数据
$sql = "select id,picturename,picturetime from pictures";
//执行sql指令,把值赋给$rs
$rs = mysqli_query($link,$sql);
$pic = array();
//对$rs进行遍历
while($row = mysqli_fetch_assoc($rs)){
//遍历结果给$pic
$pic[] = $row;
}
//print_r('<pre>');
//print_r($pic);
//调用前端文件
require ('pictures.html');
|