que..._mysq 修i该表中一条数据">
赞
踩
代号姓名性别民族生日操作
$db = new MySQLi("localhost","root","123456","crud");
$sql = "select info.code,info.name,sex,nation.name,birthday from info,nation where info.nation=nation.code";
$result = $db->query($sql);
if($result){
$arr = $result->fetch_all();
foreach($arr as $v){
$sex = $v[2]?"男":"女";
echo "
{$v[0]}{$v[1]}{$sex}{$v[3]}{$v[4]} 修改";}
}
?>
第二个文件修改页
无标题文档//取出主键值
$code = $_GET["code"];
//读取该条数据
$db = new MySQLi("localhost","root","123456","crud");
$sql = "select * from info where code='{$code}'";
$result = $db->query($sql);
$arr1 = $result->fetch_row();
?>
代号:
姓名:
性别:
男 />
女 />
民族:
$sql = "select * from nation";
$result = $db->query($sql);
if($result){
$arr = $result->fetch_all();
foreach($arr as $v){
if($v[0]==$arr1[3]){
echo "{$v[1]}";
}else{
echo "{$v[1]}";
}
}
}
?>
生日:
三、执行页面
$code = $_POST["code"];
$name = $_POST["name"];
$sex = (int)$_POST["sex"];
$nation = $_POST["nation"];
$birthday = $_POST["birthday"];
$db = new MySQLi("localhost","root","123456","crud");
$sql = "update info set name='{$name}',sex={$sex},nation='{$nation}',birthday='{$birthday}' where code='{$code}'";
$result = $db->query($sql);
if($result){
header("location:main.php");
}else{
echo "修改失败!";
}
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。