Blogger Information
Blog 29
fans 0
comment 0
visits 29289
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
数据库删除操作
咸鱼梦
Original
517 people have browsed it

用户信息表:

<?php
//连接数据库
$pageTitle = '用户信息列表';
require 'public/connect.php';
//查询用户信息表user
$sql = "SELECT * FROM user";  //创建查询语句
$result = mysqli_query($db, $sql);  //执行查询
$rows = [];  //创建查询结果容器,初始为空数组,该数组最终会成为一个二维数组,与数组表对应
if ($result && mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_array($result, MYSQLI_ASSOC))
        //print_r($row);  //查看查询到的数据
        $rows[] = $row;  //将每一次查询到的结果放在数组$rows[]中,这是最终返回的结果
} else {
    echo '<h3>数据表为空,没有数据~~</h3>';
}

//释放结果集
mysqli_free_result($result);
//关闭连接
mysqli_close($db);

?>
<?php include 'public/header.php'?>
<!--创建表格用来展示用户数据-->
<div class="container">
	<div class="row">
		<div class="com-md-12">
			<h3>用户信息表</h3>
			<table class="table table-bordered text-center">
				<tr class="h5 bg-info">
					<td>ID</td>
					<td>姓名</td>
					<td>邮箱</td>
					<td>操作</td>
				</tr>
				<?php foreach ($rows as $row) : ?>
					<tr>
						<td>
							<?php echo $row['id']?>
						</td>
						<td>
							<?php echo $row['name']?>
						</td>
						<td>
							<?php echo $row['email']?>
						</td>
						<td>
							<a class="btn btn-primary" href="edit.php?id=<?php echo $row['id']?>" role="button">编辑</a>
							<a class="btn btn-danger" href="del.php?id=<?php echo $row['id']?>" role="button">删除</a>
						</td>
					</tr>
				<?php endforeach;?>
			</table>
		</div>
	</div>
</div>

<!--公用底部-->
<?php include 'public/footer.php'?>

删除功能实现:

<?php
require 'public/connect.php';
//创建sql删除代码
$sql = "DELETE FROM user WHERE id=".$_GET['id'];
//判处执行操作
if (mysqli_query($db, $sql)){
    echo '<script>alert("成功删了'.mysqli_affected_rows($db).'条记录")</script>';
} else {
    echo '<script>alert("删除失败'.mysqli_error($db).'")</script>';
}
//关闭数据库
mysqli_close($db);


Statement of this Website
The copyright of this blog article belongs to the blogger. Please specify the address when reprinting! If there is any infringement or violation of the law, please contact admin@php.cn Report processing!
All comments Speak rationally on civilized internet, please comply with News Comment Service Agreement
0 comments
Author's latest blog post