<?php
session_start();
if ($_SESSION['login']!="ok") {
	echo "<script language='javascript'>";
	echo " location='./';";
	echo "</script>";
}
?>
<?php
//这里输出数据主要是看他的格式
require("config.php");
require("conn.php");
require("function.php");
$line=50;
$limit=$_POST['limit'];
$start=$_POST['start'];
//$start=25;
$title=$_POST['title'];
$kind=$_POST['kind'];
if($kind==99999){$kind="";}
//$limit=$_GET['limit'];
//$start=$_GET['start'];
//sleep(200);
//$title=iconv( "UTF-8", "gb2312//IGNORE" ,$title);
setcookie("_start",$start);
if($title!=""){
	if($kind!=""){
		//$kind=un_select_kind($kind);
		$count=@mysql_query("select count(id) as count from link where kind='$kind' and (name like '%$title%' or letter like '%$title%')",$db);
	}else{
		$count=@mysql_query("select count(id) as count from link where name like '%$title%' or letter like '%$title%'",$db);
	}
	
}else{
	if($kind!=""){
		//$kind=un_select_kind($kind);
		$count=@mysql_query("select count(id) as count from link where kind='$kind'",$db);
	}else{
	    $count=@mysql_query("select count(id) as count from link",$db);
	}
}

$count_nu=@mysql_fetch_array($count);
$count_number=$count_nu['count'];
$i=0;
echo "{total:$count_number,results:[";
if($start+$limit>$count_number){//这里对传过来的limit做了处理,以免超出数据库总记录的范围
	$limit=$limit-($start+$limit-$count_number);
}
if($title!=""){
	if($kind!=""){
		$req=@mysql_query("select * from link where kind='$kind' and (name like '%$title%' or letter like '%$title%') order by id DESC limit $start,$limit",$db);
	}else{
		$req=@mysql_query("select * from link where name like '%$title%' or letter like '%$title%' order by id DESC limit $start,$limit",$db);
	}
	
}else{
	if($kind!=""){
		$req=@mysql_query("select * from link where kind='$kind'  order by id DESC limit $start,$limit",$db);
	}else{
		$req=@mysql_query("select * from link  order by id DESC limit $start,$limit",$db);
	}
	
}
while($return=@mysql_fetch_array($req)){
    $a=$return['id'];
	$b=$return['url'];
	$c=$return['name'];
	//$c=iconv("GB2312","UTF-8",$c);
	$d=$return['states'];
	$d=select_states($d);
	$e=$return['letter'];	
	$f=$return['kind'];
	$f=select_kind($f,$db);
	$hot=select_hot($a);
	echo "{
                    urlid: $a,
                    webname: '$c',
                    weburl: '$b',
					states:'$d',
					key:'$e',
					hot:'$hot',
					kind:'$f'
                }";
				$i++;
	if($i<$limit){echo ",";}				
	
	}
	echo "]}";
?>
