<?php
header("Content-Type:text/html;charset=UTF-8");
//连接数据库
mysql_connect("localhost","root","123");
mysql_select_db("bbs");
$ww=mysql_query("set names 'utf8'");
function show($f_id){
//根据地址
$sql="select * from class where f_id ='".$f_id."'";
$rs=mysql_query($sql);
if($rs){
//echo $rs;
//将查询的结果封装成html标记
//echo mysql_num_rows($rs);
while($rows=mysql_fetch_assoc($rs)){
$arr=explode("-",$rows['f_id']);
$strs='';
for($i=1;$i<count($arr);$i++){
$strs.="--";
}
echo '<option value='.$rows['id'].'>'.$strs.$rows['name']."</option>";
show($rows['f_id']."-".$rows['id']);
}
} else{
exit();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="1.php" method="post">
<select name="show" id="show">
<?php
show(0);
?>
</select>
<input type="text" name="add" id="add">
<input type="submit" name="submit" id="submit" value="提交">
</form>
</body>
</html>
<?php
//print_r($_POST);
if(isset($_POST['submit'])){
//判断插入的长度
if(isset($_POST['add'])){
$sql1="select id,f_id from class where id=".$_POST['show'];
$rs1=mysql_query($sql1);
$str='';
while($rows1=mysql_fetch_assoc($rs1)){
$str=$rows1['f_id']."-".$rows1['id'];
}
$sql2="insert into class values('','".$str."','".$_POST['add']."')";
$rs2=mysql_query($sql2);
if($rs2){
echo "<script>alert('成功插入');</script>";
}
}
}
?>
header("Content-Type:text/html;charset=UTF-8");
//连接数据库
mysql_connect("localhost","root","123");
mysql_select_db("bbs");
$ww=mysql_query("set names 'utf8'");
function show($f_id){
//根据地址
$sql="select * from class where f_id ='".$f_id."'";
$rs=mysql_query($sql);
if($rs){
//echo $rs;
//将查询的结果封装成html标记
//echo mysql_num_rows($rs);
while($rows=mysql_fetch_assoc($rs)){
$arr=explode("-",$rows['f_id']);
$strs='';
for($i=1;$i<count($arr);$i++){
$strs.="--";
}
echo '<option value='.$rows['id'].'>'.$strs.$rows['name']."</option>";
show($rows['f_id']."-".$rows['id']);
}
} else{
exit();
}
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
</head>
<body>
<form action="1.php" method="post">
<select name="show" id="show">
<?php
show(0);
?>
</select>
<input type="text" name="add" id="add">
<input type="submit" name="submit" id="submit" value="提交">
</form>
</body>
</html>
<?php
//print_r($_POST);
if(isset($_POST['submit'])){
//判断插入的长度
if(isset($_POST['add'])){
$sql1="select id,f_id from class where id=".$_POST['show'];
$rs1=mysql_query($sql1);
$str='';
while($rows1=mysql_fetch_assoc($rs1)){
$str=$rows1['f_id']."-".$rows1['id'];
}
$sql2="insert into class values('','".$str."','".$_POST['add']."')";
$rs2=mysql_query($sql2);
if($rs2){
echo "<script>alert('成功插入');</script>";
}
}
}
?>