$conn=mysql_connect($mysql_host,$mysql_user,$mysql_password) or die('连接服务器出错');
mysql_select_db($mysql_db) or die("选择数据库教程出错");
mysql_query("set names 'gbk'");
function table($t)
{
global $mysql_table_prefix;
return $mysql_table_prefix.$t;
}
$sql="select * from ".table('keywords')." where 1=1 ";
$sql2="select count(*) from ".table('keywords')." where 1=1 ";
$py=trim($_request['py']);
if($act=="search" and !empty($_post['s1']))
{
$s1=trim($_post['s1']);//获取搜索字
$sql .=" and (k1='$s1' or k2='$s1') ";
$sql2 .=" and (k1='$s1' or k2='$s1') ";
}
elseif(!empty($py))
{
$sql .=" and pinyin='$py' ";
$sql2.=" and pinyin='$py' ";
}
$sql .=" order by pinyin ";
$rscount=mysql_query($sql2);
$rscount=@mysql_fetch_array($rscount);
$rscount=$rscount[0];//获取总记录数
$page=trim($_get['page']);//当前页数
$pagesize=30;//每页记录数
$pagecount=ceil($rscount/$pagesize);//获取总页数
$pageurl="";
if($page<=1)
{
$page=1;
$pageurl.=" 首页 上一页";
}else
{
$pageurl .=" 首页 上一页";
}
if($page>=$pagecount)
{
$page=$pagecount;
$pageurl .=" 下一页 尾页";
}else
{
$pageurl .=" 下一页 尾页";
}
$start_rs=($page-1)*$pagesize;//开始
$end_rs=$page*$pagesize;//结束
$sql .=" limit {$start_rs},{$end_rs} ";
$res=mysql_query($sql);
?>
|