标签:
论坛区块管理
1 <?php 2 3 //引入公共配置 4 require("../../public/config.php"); 5 require("../../public/functions.php"); 6 7 //1.链接数据库并判断 8 $link=mysqli_connect(HOST,USER,PASS) or die("链接数据库失败!"); 9 10 //2.设置字符集 11 mysqli_set_charset($link,CHARSET); 12 13 //3.选择数据库 14 mysqli_select_db($link,DBNAME); 15 16 17 18 switch($_GET[‘action‘]){ 19 20 case "addFather": 21 22 23 if(empty($_POST[‘fname‘])){ 24 echo "<script>alert(‘父分区名不能为空!‘);window.location.href=‘addFatherType.php‘</script>";die; 25 } 26 27 //4.定义sql语句发送执行 28 $sql="insert type(name) values(‘{$_POST[‘fname‘]}‘)"; 29 $result = mysqli_query($link,$sql); 30 31 //5.判断插入结果 32 if($result && mysqli_affected_rows($link)>0){ 33 34 //告诉用户,添加成功 35 echo "<script>alert(‘父分区添加成功!‘);window.location.href=‘lookType.php‘</script>";die; 36 37 } 38 break; 39 40 case "addChild": 41 42 //通过错误号判断用户有没有上传头像(0代表上传了) 43 if($_FILES[‘fpic‘][‘error‘]==0){ 44 45 //定义必须的变量 46 $path = "../../public/uploads"; 47 $upfile = $_FILES[‘fpic‘]; 48 $typeList = array("image/jpeg","image/png","image/gif"); 49 $maxSize = 0; 50 51 //执行上传 52 $res = upload($path,$upfile,$typeList,$maxSize); 53 54 //判断是否上传成功(上传失败) 55 if($res[‘error‘]==false){ 56 echo "<script>alert(‘{$res[‘info‘]}‘);window.location.href=‘../personInfo.php‘;</script>"; 57 die(); 58 } 59 60 //获取上传成功之后的文件名 61 $picname = $res[‘info‘]; 62 63 //必须上传处理好的(57x57的透明图片,不然会撑坏前台样式) 64 //将图片进行等比例缩放 65 // imageResize($path,$picname,57,57,"blog_"); 66 67 } 68 69 //获取子类名称,父类id 70 $fid = $_POST[‘fid‘]; 71 $child = $_POST[‘fname‘]; 72 73 //将这两个内容写到数据库当中 74 $sql = "insert into type (name,pid,path,blogo) values (‘{$child}‘,{$fid},‘0-{$fid}‘,‘{$picname}‘)"; 75 $result = mysqli_query($link,$sql); 76 77 //判断 78 if($result && mysqli_affected_rows($link)>0){ 79 80 echo "<script>alert(‘子类名称添加成功!‘);window.location.href=‘lookType.php‘</script>";die; 81 82 } 83 break; 84 85 case "change": 86 87 //定义sql发送执行 88 $sql="update type set name=‘{$_POST[‘tname‘]}‘ where id={$_POST[‘id‘]} "; 89 $result= mysqli_query($link,$sql); 90 91 //判断修改是否成功 92 if($result && mysqli_affected_rows($link)>0){ 93 echo "<script>alert(‘修改区块名称成功!‘);window.location.href=‘lookType.php‘</script>";die; 94 }else{ 95 echo "<script>alert(‘修改区块名称失败!‘);window.location.href=‘lookType.php‘</script>";die; 96 } 97 break; 98 99 case "delete": 100 101 //定义sql语句 102 $sql="delete from type where id={$_GET[‘id‘]}"; 103 $result= mysqli_query($link,$sql); 104 105 //判断删除是否成功 106 if($result && mysqli_affected_rows($link)>0){ 107 echo "<script>alert(‘删除成功!‘);window.location.href=‘lookType.php‘</script>";die; 108 }else{ 109 echo "<script>alert(‘删除失败!‘);window.location.href=‘lookType.php‘</script>";die; 110 } 111 112 113 break; 114 } 115 116 //6.关闭数据库 117 mysqli_close($link); 118 119 ?>
显示
1 <html> 2 <head> 3 <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> 4 <title>管理栏目</title> 5 <link href="../../public/admin/css/css.css" type="text/css" rel="stylesheet" /> 6 <link href="../../public/admin/css/main.css" type="text/css" rel="stylesheet" /> 7 <link rel="shortcut icon" href="../../public/admin/img/main/favicon.ico" /> 8 <style> 9 body{overflow-x:hidden; background:#f2f0f5; padding:15px 0px 10px 5px;} 10 #searchmain{ font-size:12px;} 11 #search{ font-size:12px; background:#548fc9; margin:10px 10px 0 0; display:inline; width:100%; color:#FFF} 12 #search form span{height:40px; line-height:40px; padding:0 0px 0 10px; float:left;} 13 #search form input.text-word{height:24px; line-height:24px; width:180px; margin:8px 0 6px 0; padding:0 0px 0 10px; float:left; border:1px solid #FFF;} 14 #search form input.text-but{height:24px; line-height:24px; width:55px; background:url(../../public/admin/img/main/list_input.jpg) no-repeat left top; border:none; cursor:pointer; font-family:"Microsoft YaHei","Tahoma","Arial",‘宋体‘; color:#666; float:left; margin:8px 0 0 6px; display:inline;} 15 #search a.add{ background:url(../../public/admin/img/main/add.jpg) no-repeat 0px 6px; padding:0 10px 0 26px; height:40px; line-height:40px; font-size:14px; font-weight:bold; color:#FFF} 16 #search a:hover.add{ text-decoration:underline; color:#d2e9ff;} 17 #main-tab{ border:1px solid #eaeaea; background:#FFF; font-size:12px;} 18 #main-tab th{ font-size:12px; background:url(../../public/admin/img/main/list_bg.jpg) repeat-x; height:32px; line-height:32px;} 19 #main-tab td{ font-size:12px; line-height:40px;} 20 #main-tab td a{ font-size:12px; color:#548fc9;} 21 #main-tab td a:hover{color:#565656; text-decoration:underline;} 22 .bordertop{ border-top:1px solid #ebebeb} 23 .borderright{ border-right:1px solid #ebebeb} 24 .borderbottom{ border-bottom:1px solid #ebebeb} 25 .borderleft{ border-left:1px solid #ebebeb} 26 .gray{ color:#dbdbdb;} 27 td.fenye{ padding:10px 0 0 0; text-align:right;} 28 .bggray{ background:#f9f9f9} 29 #addinfo{ padding:0 0 10px 0;} 30 input.text-word{ width:50px; height:24px; line-height:20px; border:#ebebeb 1px solid; background:#FFF; font-family:"Microsoft YaHei","Tahoma","Arial",‘宋体‘; text-align:center; color:#666} 31 .tda{width:100px;} 32 .tdb{ padding-left:20px;} 33 td#xiugai{ padding:10px 0 0 0;} 34 td#xiugai input{ width:100px; height:40px; line-height:30px; border:none; border:1px solid #cdcdcd; background:#e6e6e6; font-family:"Microsoft YaHei","Tahoma","Arial",‘宋体‘; color:#969696; float:left; margin:0 10px 0 0; display:inline; cursor:pointer; font-size:14px; font-weight:bold;} 35 </style> 36 </head> 37 <body> 38 <!--main_top--> 39 <form method="post" action=""> 40 <table width="99%" border="0" cellspacing="0" cellpadding="0" id="searchmain"> 41 <tr> 42 <td width="99%" align="left" valign="top" id="addinfo">您的位置:板块管理 > 浏览分区</td> 43 </tr> 44 <tr> 45 <td align="left" valign="top"> 46 <table width="100%" border="0" cellspacing="0" cellpadding="0" id="main-tab"> 47 <tr> 48 49 <th align="center" valign="middle" class="borderright tda">分类树</th> 50 <th align="center" valign="middle" class="borderright tda">ID</th> 51 <th align="center" valign="middle" class="borderright">栏目名</th> 52 <th align="center" valign="middle">栏目管理</th> 53 </tr> 54 <?php 55 56 //引入公共配置 57 require("../../public/config.php"); 58 59 60 //1.链接数据库并判断 61 $link=mysqli_connect(HOST,USER,PASS) or die("链接数据库失败!"); 62 63 //2.设置字符集 64 mysqli_set_charset($link,CHARSET); 65 66 //3.选择数据库 67 mysqli_select_db($link,DBNAME); 68 69 //4. 定义sql语句,并发送执行 70 $sql = "select *,concat(path,‘-‘,id) as npath from type order by npath"; 71 $result = mysqli_query($link,$sql); 72 73 //5. 判断 74 if($result && mysqli_num_rows($result)>0){ 75 76 //解析结果集 77 while($rows = mysqli_fetch_assoc($result)){ 78 79 //显示类别信息 80 if($rows[‘pid‘]==0){ 81 82 83 ?> 84 <tr class="bggray"> 85 86 <td align="left" valign="middle" class="borderright borderbottom tdb"><img src="../../public/admin/img/main/dirfirst.gif" width="15" height="13"></td> 87 <td align="center" valign="middle" class="borderright borderbottom"><?php echo $rows[‘id‘]; ?></td> 88 <td align="left" valign="middle" class="borderright borderbottom tdb"><?php echo $rows[‘name‘]; ?></td> 89 <td align="center" valign="middle" class="borderbottom"><a href="change.php?id=<?php echo $rows[‘id‘];?>" target="mainFrame" onFocus="this.blur()" class="add">修改</a><span class="gray"> | </span><a href="addChildType.php?id=<?php echo $rows[‘id‘]; ?>&name=<?php echo $rows[‘name‘]; ?>" target="mainFrame" onFocus="this.blur()" class="add">添加子版块</a> 90 <?php 91 92 93 94 //通过id=pid检索,如果有数据不能删除 95 $sql="select id from type where pid={$rows[‘id‘]}"; 96 $res= mysqli_query($link,$sql); 97 98 //判断是否有数据 99 if($res && mysqli_num_rows($res)<=0 ){ 100 101 102 ?> 103 <span class="gray"> | </span><a href="doAction.php?action=delete&id=<?php echo $rows[‘id‘] ?>" target="mainFrame" onFocus="this.blur()" class="add">删除</a> 104 <?php 105 } 106 ?> 107 </td> 108 </tr> 109 <?php 110 }else{ 111 ?> 112 <tr> 113 114 <td align="left" valign="middle" class="borderright borderbottom tdb"><img src="../../public/admin/img/main/dirsecond.gif" width="29" height="29"></td> 115 <td align="center" valign="middle" class="borderright borderbottom"><?php echo $rows[‘id‘] ?></td> 116 <td align="left" valign="middle" class="borderright borderbottom tdb"><?php echo $rows[‘name‘] ?> </td> 117 <td align="center" valign="middle" class="borderbottom"><a href="change.php?id=<?php echo $rows[‘id‘]?>" target="mainFrame" onFocus="this.blur()" class="add">修改</a><span class="gray"> | </span><a href="add.html" target="mainFrame" onFocus="this.blur()" class="add">查看帖子</a><span class="gray"> | </span><a href="doAction.php?action=delete&id=<?php echo $rows[‘id‘] ?>" target="mainFrame" onFocus="this.blur()" class="add">删除</a></td> 118 </tr> 119 <?php 120 } 121 122 } 123 124 } 125 126 127 //6.释放结果集,关闭数据库 128 mysqli_free_result($result); 129 mysqli_close($link); 130 ?> 131 </table></td> 132 </tr> 133 <tr> 134 <td align="left" valign="top" id="xiugai"><a href="addFatherType.php"><input type="button" value="添加父分区" class="text-but"></a></td> 135 </tr> 136 </table> 137 </form> 138 </body> 139 </html>
标签:
原文地址:http://www.cnblogs.com/yexiang520/p/5592390.html