1.查看数据
显示info信息
代号 | 姓名 | 性别 | 民族 | 生日 | 操作 |
$db = new MySQLi("localhost","root","123","mydb"); 造连接对象
$sql = "select * from 表名"; 查询表中的所有数据
$result = $db->query($sql); 执行sql语句
$arr = $result->fetch_all();
foreach($arr as $v) 遍历
{
//修改性别
$sex = $v[2]?"男":"女"; 性别等于男的情况下输出男,反之输出女
//修改民族
$sql1 = "select name from nation where code='{$v[3]}'";
$r1 = $db->query($sql1);
$a1 = $r1->fetch_row();
echo "
{$v[0]}{$v[1]}{$sex}{$a1[0]}{$v[4]} 删除 不能都是双引号,转义字符"; onclick不仅可以写函数,可以写任何JS代码}
?>
//confirm("确定删除么");
2.处理
$code = $_GET["code"]; 在主表中的删除传送方式使用的get,所以这里用get传送
$db = new MySQLi("localhost","root","123","mydb"); 造新的链接
$sql = "delete from info where code='{$code}'"; 写sql语句,因为是代号不会重复,所以查找代号等于定义的code
if($db->query($sql)) 执行sql语句
{
跳转页面
header("location:main.php"); 删除成功返回到主表的页面,location:地址。
//echo ""; href=后面加地址。
}
else
{
echo "删除失败!";
}