<?php 
		foreach($catemidnameArray2 as $k=>$val){
			$i++;
			if($i%2 != 0){
				$name = $val['catename'];
				echo $val['catename']."<br/>";
			}
			
			if($i%2 == 0){
				$catemidname2 = $val['catemidname'];
				$picNameOld=$_POST['PicOld'];
				$ls=$_POST['ls'];
				//$midcateName=replaceCatesName($_POST['midcateName']);
				$midcateName=trim($val['catemidname']);
				$ChangecatePagePic=$_POST['ChangecatePagePic'];
				
				//获得大类名称，用来判读此类下是否有同名的中类
				$cateName = trim($val['catemidname']);
				$cateTitle=$cateName." - ".$brand;
				$cateKeywords=$cateName ;
				$cateDescription=$cateName ;
			
			
				$midcateBrief=str_replace("\n","<br />",htmlspecialchars($_POST['midcateBrief'], ENT_QUOTES));
				$midcateDetail=$_POST['midcateDetail'];
			
				$midcateFolders=$cateName ;
				if($midcateFolders=="")				//如果没有设目录则截取
				{$midcateFolders=$midcateName;}
				$midcateFolders=trim(clearFolder(strtolower($midcateFolders)));
				
				$title_sql = "select * from ls_products where cateName='".$name."'";
				$opendb = new mydb();
				$title_query = $opendb->query($title_sql);
				$title_value = mysqli_fetch_assoc($title_query);
				
				$midcateID=$title_value['ID'];
				$cate_id=$title_value['ID'];
				$cateName=trim($val['catename']);
				
				if($midcateID!="")
				{
					$cate_sql="select * from ls_products where ID='".$cate_id."' ";
					$cate_query=$opendb->query($cate_sql);
					$cate_rows=mysqli_fetch_assoc($cate_query);
					$cateFolders=$cate_rows['cateFolders'];
				}
				
				$path = "../".$cateFolders."/".$midcateFolders;
				$ls = "insert";
				
				switch ($ls)
				{
					case "insert":
									
						$midcateName = str_replace("'","''",$midcateName);
						// 开始判断是否有重复的
						$select_sql="select * from ls_products where midcateName='".$midcateName."' and cateName='".$cateName."'";
						$select_query=$opendb->query($select_sql);
						$select_rows=mysqli_num_rows($select_query);
						if($select_rows==0)
						{
			
							//调用建立文件夹函数 createFolder
							createFolder($path);
					
							$insert_sql=sprintf("insert into ls_products (cateTitle,cateKeywords,cateDescription,midcateName,midcateFolders,midcateBrief,catePic,midcateDetail,midcateID,Num,enable) values (%s,%s,%s,%s,%s,%s,%s,%s,%s,%s,%s) ",
															GetSQLValueString($cateTitle, "text"),
															GetSQLValueString($cateKeywords, "text"),
															GetSQLValueString($cateDescription, "text"),
															GetSQLValueString(ucwords($midcateName), "text"),
															GetSQLValueString($midcateFolders, "text"),
															GetSQLValueString($midcateBrief, "text"),
															GetSQLValueString($picName, "text"),
															GetSQLValueString($midcateDetail, "text"),
															GetSQLValueString($midcateID, "text"),
															GetSQLValueString($select_rows2+1, "int"),
															GetSQLValueString("1", "int")
														 );
								//echo $insert_sql;
								$insert_query=$opendb->query($insert_sql);
								//writelog($_SERVER['PHP_SELF'],"add mid-category: ".$midcateName,"ID: ".$id);
								echo "添加中类".ucwords($midcateName)."成功。<br />";
								/*echo "<script>alert('数据添加成功！');location='cate.php';</script>";  */
							}
							else
							{
								/*echo "<script>alert('已存在此中类名！\\n请填写别的中类名！');history.go(-1);</script>";	*/
							}
				
							break;
		
				}
			}
		}

?>