时间:2021-07-01 10:21:17 帮助过:32人阅读
session_start();
//连接数据库服务器
$Link=mssql_connect(".","sa","");
//选择数据库
mssql_select_db("frienddb");
//定义SQL语句
$name=$_REQUEST["txtName"];
$address=$_REQUEST["txtAddress"];
$group=$_REQUEST["txtGroup"];
$sqlstr="";
if($name!="")
{
$sqlstr="mName='".$name."'";
}
if($sqlstr!="")
{
if($address!="")
{
$sqlstr=$sqlstr." and mAddress='".$address."'";
}
}
else
{
if($address!="")
{
$sqlstr="mAddress='".$address."'";
}
}
if($sqlstr!="")
{
if($group!="")
{
$sqlstr=$sqlstr." and tname='".$group."'";
}
}
else
{
if($group!="")
{
$sqlstr="tname='".$group."'";
}
}
if($_REQUEST["Submit"]!="")
{
$_SESSION["sqltxt"]=$sqlstr;
}
else
{
$sqlstr=$_SESSION["sqltxt"];
}
echo $_SESSION["sqltxt"];
if($sqlstr!="")
{
$Query="select count(*) from myfriends,team where myfriends.tid=team.tid and ".$sqlstr;
}
else
{
$Query="select count(*) from myfriends,team where myfriends.tid=team.tid ";
}
$rs=mssql_query($Query);//查询记录总数
$cntrow=mssql_fetch_row($rs);
$cnt=$cntrow[0];//记录总数
$PageSize=10;//每页显示10条数据
//计算总页数
if($cnt%$PageSize==0)
{
$PageCnt=$cnt/$PageSize;
}
else
{
$PageCnt=floor($cnt/$PageSize)+1;//总页数
}
$CurrentPage=floor($_REQUEST["pid"]);//当前页,如果为小数则当前页取值为小于此小数的整数
//当前页小于1
if($CurrentPage<1)
{
$CurrentPage=1;
}
//当前页大于总页数
if($CurrentPage>$PageCnt)
{
$CurrentPage=$PageCnt;
}
//设置起始页码
$Start=$CurrentPage-3;
//设置终止页码
$End=$CurrentPage+3;
//上一页
$PrvPage=$CurrentPage-1;
//下一页
$NextPage=$CurrentPage+1;
if($Start<1)
{
$Start=1;
$End=$Start+6;
}
if($End>$PageCnt)
{
$Start=$PageCnt-6;
$End=$PageCnt;
}
if($sqlstr!="")
{
$sqlstr="select top ".$PageSize." mName,mSex,mBirthday,mTel,mAddress,tname from myfriends,team where myfriends.tid=team.tid and mid not in (select top ".($CurrentPage-1)*$PageSize." mid from myfriends) and ".$sqlstr;
}
else
{
$sqlstr="select top ".$PageSize." mName,mSex,mBirthday,mTel,mAddress,tname from myfriends,team where myfriends.tid=team.tid and mid not in (select top ".($CurrentPage-1)*$PageSize." mid from myfriends) ";
}
//echo $sqlstr;
$result=mssql_query($sqlstr);//返回结果集
/*
mssql_fetch_row//取行数据
mssql_fetch_field//取列数据
*/
?>