<?php
require '../common.inc.php';
header("Content-type:text/html; charset=utf-8");
//require 'global.func.php';
$gameids = strip_tags($_GET['gameid']);
//$gameids = strip_tags($_POST['gameid']);
$groupid = strip_tags($_POST['groupid']);
$serverid = strip_tags($_POST['serverid']);
$gtid = strip_tags($_POST['gtid']);
$carrierid = strip_tags($_POST['carrierid']);
switch($gameid) {
	case '$gameid ':
	$gameid = substr($gameids,1);
	$first = substr($gameids,0,1);
}
$query = mysql_query("select * from {$db->pre}category where catid=$gameid");
while($row=mysql_fetch_array($query)){

	      $parentid=$row['catid'];
		  $game = $row['catid'];
		  /**********************/
		  if($row['parentid']==6){	
		  ////////////////////***
		  $querys = mysql_query("select * from {$db->pre}category where parentid=$parentid ORDER BY listorder,catid ASC");
          while($yun=mysql_fetch_array($querys)){
		   ///////////////////////**
		   $pids = $yun['catid'];
    	  $sql = mysql_query("select * from {$db->pre}category where parentid=$pids ORDER BY listorder,catid ASC");
          while($r=mysql_fetch_array($sql)){
			  ///////////////////////*
		  $pid=$r['catid'];  
    	  $sqls = mysql_query("select * from {$db->pre}category where parentid=$pid ORDER BY listorder,catid ASC");
          while($sall=mysql_fetch_array($sqls)){

		  //三级分类
			    	  
	      $small[$pid][] = array(
	 	 'serverid' => $sall['catid'], 
		 'servername' => $sall['catname'], 
	 );
	
	 
}



///////////////////////////*
		  
		 //游戏二级分类	  
	      $sub[$pids][] = array(
	 	 'groupid' => $r['catid'], 
		 'groupname' => $r['catname'],
		 'servers' =>  $small[$r['catid']],
	 );


}
 ///////////////////////**
        //手游戏运营商	  
	      $run[$parentid][] = array(
	 	 'carrierid' => $yun['catid'], 
		 'carriername' => $yun['catname'],
	     'groups' => $sub[$yun['catid']], 
        );

		
		  }
//////////////////***		  
     //游戏名称
	 $arr = array(
	 	'gameid' => $game, 
		'gamename' => $row['catname'], 
		'carriers' => $run[$row['catid']], 
	 );

	
		}
		  else
		        {
    	  $sql = mysql_query("select * from {$db->pre}category where parentid=$parentid  ORDER BY listorder,catid ASC");
          while($r=mysql_fetch_array($sql)){
		  $pid=$r['catid'];  
    	  $sqls = mysql_query("select * from {$db->pre}category where parentid=$pid  ORDER BY listorder,catid ASC");
          while($sall=mysql_fetch_array($sqls)){

		  //三级分类	  
	      $small[$pid][] = array(
	 	 'serverid' => $sall['catid'], 
		 'servername' => $sall['catname'],
	 );
}
			  
		 //游戏二级分类	  
	      $sub[$parentid][] = array(
	 	 'groupid' => $r['catid'], 
		 'groupname' => $r['catname'],
		 'servers' => $small[$r['catid']],  
	 );
}
     //游戏名称
	 $arr = array(
	 	'gameid' => $game, 
		'gamename' => $row['catname'], 
		'groups' => $sub[$row['catid']], 
	 );


}

/*********************/	
	}


echo preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", json_encode($arr));
?>