if(isset($submit)){
foreach($typeName as $k =>$v){//遍历前台列表数组内容
if($v!=''){
$typeText.=$v.$typeTextStr;// 拼接内容,拼接间隔符在common中定义
}
}
$typeText=rtrim($typeText,$typeTextStr);//去掉拼接后多余的标志
if($db->get_one("SELECT type FROM {$TB_PRE}personnelbase WHERE type='$type'")) {//判断数据库中是否有类型
$addSql = "UPDATE {$TB_PRE}personnelbase SET typetext='$typeText' WHERE type='$type'";
} else {
$addSql="INSERT INTO {$TB_PRE}personnelbase (type,typetext) VALUES('$type','$typeText')";
}
if($db->query($addSql)) {
show_msg("添加成功...",'personnelbase.php?type='.$type,0,3000);
}else {
show_msg("添加失败...".mysql_error(),-1,0,5000);
}
}else{
$type=$type?$type:"民族";//如果没有选择,默认是民族
$selSql="SELECT typetext FROM {$TB_PRE}personnelbase WHERE type='$type'";
$contents=$db->get_one($selSql);
$arr_str=explode($typeTextStr,$contents['typetext']);//拆分数据库中取出的记录内容,拆分之后是一个数组
}
<script type="text/javascript" src="/js/jquery.js"></script>
<script type="text/javascript">
$(function(){ //js的部分调用,要注意其中各个id 的使用
$("#addNew").click(function(){//添加操作
var str = $(".str:last").clone(true);
str.find("input").eq(0).val("");
str.insertAfter($(".str:last"));
get_num();
});
get_num();
});
$(".toClose").live("click",function(){//删除操作
if($(".str").length>1) {
$(this).parent().parent().remove();
get_num();
}
});
function get_num() {//序号的显示
for(i=1;i<=$(".str").length;i++) {
var j=i-1;
$(".str:eq("+j+")>td:first").html(i);
}
}
</script>
</head>
<form action="personnelbase.php?type={tpl:$type}" method="post">
{tpl:loop $typeArr $k $v}
<li align="center" {tpl:if $v==$type}class="but2"{tpl:else}class="but"{tpl:/if} width='80%'><a href="personnelbase.php?type={tpl:$v}">{tpl:$v}</a></li>
{tpl:/loop}
<table width="48%" border="1" cellpadding="1" bordercolor="#dadada" style="border-collapse:collapse; margin:0 auto;">
<tr align="center" height="32" style="margin-top:60px;">
<th>序号</th>
<th>{tpl:$type}名称</th>
<th>操作</th>
<tr>
<input type='hidden' name='type' value='{tpl:$type}'/>
{tpl:loop $arr_str $k $v}
<tr align="center" class="str" height="30">
<td></td>
<td><input class ="t_input" type="text" value="{tpl:$v}" name="typeName[]" id="list"/></td>
<td><a href="javascript:void(0)" class="toClose">删除</a></td>
<tr>
{tpl:/loop}
<tr>
<td align="center" colspan="3">
<input class="but" type="submit" value="更新" name="submit"/>
<input class="but" type="button" value="增加" id="addNew"/>
</td>
</tr>
</table>
其中选中某一个属性,则可以实现增加行,删除行,插入数据库