ڵλã  >> վѧԺ >> վ >> PHP̳ >> PHPۺϽ̳ >> 

phpͶƱϵͳ֮ɾͶƱԱƪ

ߣ Դ ʱ䣺2016-7-7

ͶƱϵͳôôԾͲ˵ⲻDZҵƣҪ˵һʹphpʵͶƱϵͳͨϵͳһΪ֣һԱһͨû֡

ͶƱϵͳĹ֣dz֮򵥣ṩֵĹܣͶƱɾͶƱ

ؼƺݿıⶨһͶƱvoteparentͶƱı⡢ǷɾvotechildrenͶƱѡͶƱ

һĿ

ͶƱϵͳģ


ӣȥֱܹӽعܵIJдԱ֣ͨûʹõjpgraphһ˵

м䰴˵Ӧе¼ϵͳģﲻص㣬Բο֮ǰġphp¼ϵͳϢӣ

㿪ͶƱѡ½棬ܹɾͶƱѡ10ͶƱѡ2ͷѡ벻ʾ


ԤͼʹIE6ģɾѡӦñȽԱͶƱϢ֮󣬾ܳɹͶƱˡ


ύǰԱѯǷӣֹϵͳʵӦʹxajaxͶƱǷУһѡΪӦòӣԲοphpעϵͳʹXajaxʱ֤ûǷռáһģӣûΪҪͶƱϵͳʵ֣ͲЩСϸڡ

ٵ㿪ͶƱϵͳɾͶƱ֣


ÿһͶƱĩβɾťÿһͶƱܹ鿴ͶƱ


ɾťͬѯʣȻ󣬵ȡʲôᷢȷܹɹɾͶƱ


ͼܹԷɾǰ4ͶƱȻɾ֮һͶƱ

˼

ͶƱϵͳĹԱûʲôµļݿIJvoteparentĽṹ£


idУtitleͶƱĴ⣬ġ˧˧֮֮࣬textŶͶƱδ˲ʹжϿɾͶƱɲ飬ΪɾķʽɾλisdelֳģɾλΪ0ͶƱ

votechildren£idУtextÿһѡcountѡƱparentidѡĸͶƱġȻvoteparentŲοԼûбҪòʱ鷳


ֵעǣű֮󣬼ǵ÷table optionsǩűı붼Ϊutf-8


վĿ¼ṹʾ


ֻ˵createvote.html,createvote.php,delvote.php,delvotehandle.php,index.htmlҳ

 
1index.html
ģӵindex.htmlͲ˵ˣaǩѧhtml˶ˣ£ 

<!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>
<a href="createvote.html">ͶƱԱ֣</a><br />
<a href="delvote.php">ɾͶƱԱ֣</a><br />
<a href="voteindex.php">ͶƱͨû֣</a>
</body>
</html>

 2createvote.html
 ͶƱҳͶƱҳjsİť⣬һлһ¼жٸѡ
 ΪһͶƱҳcreatevote.phpṩ
 л˵javascriptwebڵIJԲο֮ǰġJavaScriptҳڵɾIJ÷ʵһģӣ
 ע⵽ӵѡڵйɵopt1,opt2,opt3УΪ˷IJ 

<!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>
<h1>ͶƱ</h1>
<button onclick="createbtn()">ѡ</button> <button onclick="delbtn()">ɾѡ</button>
<!--onsubmitΪűܹ˳ȷϿûȷ֮ύ-->
<form action="createvote.php" method="post" onsubmit="return check()">
<!--ﶨdividΪjavascriptIJdivpμӺܴо-->
<div id="createform">
<div>
ͶƱ⣺<input type="text" name="title" style = "width:70%"/>
</div>
<div>
ͶƱ<input type="text" name="text" style = "width:70%"/>
</div>
<div>
ѡ1<input type="text" name="opt1" style = "width:70%"/>
</div>
<div>
ѡ2<input type="text" name="opt2" style = "width:70%"/>
</div>
</div>
<!--¼жٸѡ-->
<input type="hidden" id="nodetotal" name="nodetotal" />
<input type="submit" value="ύ" />
</form>
<a href="index.html"></a>
</body>
</html>

<script>
//ű֣ʵĹؼ
//ʼȼ¼ǰѡ2hidden򣬵ʱһύ
var nodenum=2;
document.getElementById("nodetotal").value=nodenum;
//ǡѡɾѡİť
function createbtn(){
 //ѡ10Ų
 if(nodenum<10){
 nodenum++;
 var node=document.createElement("div");
 //ڵ漰htmlıдɵžͲд\"ôѿ˫ŵתַ
 node.innerHTML="ѡ"+nodenum+"<input type='text' name='opt"+nodenum+"' style='width:70%' />";
 document.getElementById("createform").appendChild(node);
 //ǵÿڵ㣬ҪhiddenĽڵŶ
 document.getElementById("nodetotal").value=nodenum;
 }
 else{
 alert("10ѡ");
 }
}
//߼һ
function delbtn(){
 if(nodenum>2){
 nodenum--;
 d=document.getElementById("createform");
 d.removeChild(d.lastChild);
 document.getElementById("nodetotal").value=nodenum;
 }
 else{
 alert("2ѡ");
 }
}
//ȷϿĽűonsubmitΪtrueܹύconfirmȷ򷵻true֮Ϊfalse
function check(){
 return confirm("ȷύ");
}
</script>

3createvote.php
 ͶƱҳݿҪע⣬Ȳvoteparentҳղvoteparent¼idvotechildrenparentidparentidҪע⣬ҪͨѰһ¼ķҵparentidΪԱڲݿIJʱģݿ֮ǰǵümysql_query("set names utf8");仰뿴룺

 <!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>
<?php
//ȡղҪͶƱtitletextеѡ
$ptitle=$_REQUEST["title"];
$ptext=$_REQUEST["text"];
$nodetotal=$_REQUEST["nodetotal"];
$con=mysql_connect("localhost","root","root");
//ݿ
if(!$con){
 die("ʧܣ");
 }
mysql_select_db("test",$con);
mysql_query("set names utf8");
//titletext뵽voteparent趨ɾλ0֮ϵͳԶid
mysql_query("insert into voteparent(title,text,isdel) values ('".$ptitle."','".$ptext."',0);");
//ͨtitleҵղϵͳɵid
$pid;
$result=mysql_query("select id as pid from voteparent where title='".$ptitle."';");
while($row=mysql_fetch_array($result)){
 $pid=$row["pid"];
}
//һphp飬ÿһѡ
$optarr=array();
//ѡĶپǵѭ
for($i=1;$i<$nodetotal+1;$i++){
 $optarr[$i]=$_REQUEST["opt${i}"];
 mysql_query("insert into votechildren(text,count,parentid) values ('".$optarr[$i]."',0,'".$pid."');");
 }; 
mysql_close($con); 
?>
</body>
</html>
<script>
alert("ӳɹ");
window.location.href="index.html";
</script>

 ϣԱͶƱ꣬ǹԱɾͶƱ
 4delvote.php
ȰvoteparentеɾλΪ1ͶƱѯȻУΪϣȿӵͶƱɽڵʱúÿһͶƱɾťididݿеvoteparentidɾťĽűдʲôǰiddelvotehandle.phpɾҳоͿ

 <!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>
<h1>ɾͶƱ</h1>
<?php
$con=mysql_connect("localhost","root","root");
if(!$con){
 die("ʧܣ");
}
mysql_select_db("test",$con);
mysql_query("set names utf8");
$result=mysql_query("SELECT * FROM voteparent where isdel=0 order by id desc;");
$i=1;
while($row=mysql_fetch_array($result)){
 echo "<div style='margin-right:10px;float:left'>ͶƱ${i}<a href='vote.php?id=${row["id"]}'>${row["title"]}</a></div><div style='float:left'><button id='${row["id"]}' onclick='deljs(this.id)'>ɾ</button></div><div style='clear:both'></div>";
 $i++;
}
mysql_close($con);
?>
<p>
<a href="index.html"></a>
</p>
</body>
</html>
<script>
function deljs(id){
 if(confirm("ȷɾ")){
 window.location.href="delvotehandle.php?id="+id;
 }
 }

</script>˼ҳdiv֣tableԲο֮ǰġCSSdivĶҳ֡ӣ 

5delvotehandle.php
 ȡղŴididӦisdelɾλ趨Ϊ1

 <!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>
<?php
$pid=$_REQUEST["id"];
$con=mysql_connect("localhost","root","root");
if(!$con){
 die("ʧܣ");
 }
mysql_select_db("test",$con);
mysql_query("set names utf8");
mysql_query("update voteparent set isdel=1 where id=".$pid.";");
mysql_close($con); 
?>
</body>
</html>
<script>
alert("ɾɹ");
window.location.href="index.html";
</script>

 ϾͶƱϵͳԱ֣ͶƱɾͶƱḶ́˵صĴҳ棬Ҫsessionı
ֱַܹʣûдԲο֮ǰġphp+MySqlʵֵ¼ϵͳϢܡӣ

ϾDZĵȫݣϣԴҵѧϰҲϣҶ֧֡

תע:(лл)
ۣ

Ȩ

ϵ

ϵ

Ȩ

QQȺ

ʽ

ҵ

Ʒ