<?php
error_reporting(0);
//list函数。调用方法：
//lis($sql,$biaoqian,$shujuku_ip,$shujuku_zhanghao,$shujuku_mima,$shujuku_ming,$k);
function lis($sql,$shujuku_ip,$shujuku_zhanghao,$shujuku_mima,$shujuku_ming,$k,$shujuku_qianzhui)
{
$li="";
$i=0;
$con = mysql_connect($shujuku_ip,$shujuku_zhanghao,$shujuku_mima);
//if (!$con)如果链接出了问题，不需要报错
//  {
//  die('Could not connect: ' . mysql_error());
//  }
mysql_query("set names GB2312");//如果要查询的是中文，则加上这一句就不会乱码
mysql_select_db($shujuku_ming, $con);
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
  {
  $i++;
  //替换标签
  $bi=$row['title'];
  
  
  if(mb_strlen($bi,"GB2312")>19)
  {
  $bi = mb_substr($bi,0,19,"GB2312");
  }
  $t=str_replace("<biaoti>",$bi,$k);
  $t=str_replace("<id>",$row['id'],$t);
  $t=str_replace("<suoluetu>",$row['litpic'],$t);
  //判断评分
  $aver=$row['total']/$row['voter'];
  $aver=round($aver,1)*10;
  $aver=$aver/10;
  $aver=str_replace('.','<em>.',$aver);
  $t=str_replace("<pingfen>",$aver,$t);
  //设置人气
  $iRq=0;
	if($row['click'] > 0 && $row['click'] <= 100)
	{
	$iRq=1;
	}
	else if($row['click'] > 100 && $row['click'] <= 200)
	{
	$iRq=2;
	}
	else if($row['click'] > 200 && $row['click'] <= 300)
	{
	$iRq=3;
	}
	else if($row['click'] > 300 && $row['click'] <= 400)
	{
	$iRq=4;
	}
	else if($row['click'] > 400 && $row['click'] <= 500)
	{
	$iRq=5;
	}
	else if($row['click'] > 500 && $row['click'] <= 600)
	{
	$iRq=6;
	}
	else if($row['click'] > 600 && $row['click'] <= 700)
	{
	$iRq=7;
	}
	else if($row['click'] > 700 && $row['click'] <= 800)
	{
	$iRq=8;
	}
	else if($row['click'] > 800 && $row['click'] <= 900)
	{
	$iRq=9;
	}
	else if($row['click'] > 900)
	{
	$iRq=10;
	}
	$t=str_replace("<renqi>",$iRq,$t);
	//设置人气结束
  $t=str_replace("<l_id>",$i,$t);
  $li = $li . $t;
  }
$GLOBALS['yingxiangshu']=$i;
return $li;
mysql_close($con);
}





function phpescape($str)
{
         $sublen=strlen($str);
         $retrunString="";
         for ($i=0;$i<$sublen;$i++)
         {
                  if(ord($str[$i])>=127)
                  {
                           $tmpString=bin2hex(iconv("gb2312","ucs-2",substr($str,$i,2)));
                           //$tmpString=substr($tmpString,2,2).substr($tmpString,0,2);window下可能要打开此项
                           $retrunString.="%u".$tmpString;
                           $i++;
                  } else {
                           $retrunString.="%".dechex(ord($str[$i]));
                  }
         }
         return $retrunString;
}


?>