一:页面文件(test.php)
<html>
<head>
<style TYPE="text/css">
<!--
A:link{text-decoration:none}
A:visited{text-decoration:none}
A:hover {color: #ff00ff;text-decoration:underline}
-->
</style>
</head>
<body onLoad="initpage()">
<script type="text/javascript" src="./js/calendar.js"></script>
<script type="text/javascript" src="./js/ajax.js"></script>
<script language="javascript">
function getCurDate(n)//获得客户端时间,n表示与当前日期差几天
{
var d = new Date();
d.setDate(d.getDate()+n);
d = d.getFullYear()+"" +add_zero(d.getMonth()+1) +""+ add_zero(d.getDate());
return d;
}
function add_zero(temp)
{
if(temp<10) return "0"+temp;
else return temp;
}
function initpage(){
document.getElementById("starttime").value = getCurDate(-27);
document.getElementById("endtime").value = getCurDate(0);
var startTime = document.getElementById("starttime").value;
var endTime = document.getElementById("endtime").value;
var nowPage = document.getElementById("nowpage").value;
var pageSize = document.getElementById("pagesize").value;
showHint(startTime,endTime,nowPage,pageSize);
}
</script>
<input type="hidden" name="nowpage" id="nowpage" value="1">
<input type="hidden" name="pagesize" id="pagesize" value="5">
<div style="width:600" align="center">
开始时间:
<input name="starttime" id="starttime" type="text" onFocus="calendar(event)" value="">
结束时间:
<input name="endtime" id = "endtime" type="text" onFocus="calendar(event)" value="">
<input type = "button" value ="查询" onclick = "showHint(starttime.value,endtime.value,nowpage.value,pagesize.value)" />
<span id="txtHint" name="txtHint">
</span>
</div>
</body>
</html>
二:PHP取数据文件(getData.php)
<?php
include "class/adodb/adodb.inc.php";
header('Content-Type:text/html;charset=GB2312');
$starttime = $_GET["starttime"];
$endtime = $_GET["endtime"];
$nowpage = $_GET["nowpage"];
$pagesize = $_GET["pagesize"];
function pageination($recordcount,$tabNum,$pagesize,$nowpage){
$strHtml = "";
$num=$recordcount;//总记录条数
$showpage=$tabNum*2+1;//页面上的标签个数
if($num==0){
return false;
}else{//else1
if($num%$pagesize){
$all_pages = (int)($num / $pagesize)+1;
}else{
$all_pages = $num / $pagesize;
}
$strHtml.="<table align='center'><tr><td width='70%' align='right'>";
$strHtml.="<font size='-1' style='font-family:'宋体''>共".$all_pages."页 ";
if($all_pages!=1){//if all_pages
if($nowpage!=1)
$strHtml.="<a href=# onclick='showHint(starttime.value,endtime.value,1,pagesize.value)'>首页</a>
<a href=# onclick='showHint(starttime.value,endtime.value,"
.($nowpage-1).",pagesize.value)'>上一页 </a>";
if($all_pages<=$showpage)
for($i=1;$i<=$all_pages;$i++){
if ($nowpage==$i){
$strHtml.="<span>$i</span>";
}else{
$strHtml.="<a href=# onclick='showHint(starttime.value,endtime.value,"
.$i.",pagesize.value)'>[".$i."]</a>";
}
}else{
$bpage=$nowpage-$tabNum;
$epage=$nowpage+$tabNum;
if($bpage<=1)
for($i=1;$i<=$showpage;$i++){
if ($nowpage==$i){
$strHtml.="<span>$i</span>";
}else{
$strHtml.="<a href=# onclick='showHint(starttime.value,endtime.value,"
.$i.",pagesize.value)'>[".$i."]</a>";
}
}else if($epage<=$all_pages)
for($i=$bpage;$i<=$epage;$i++){
if ($nowpage==$i)
$strHtml.="<span>$i</span>";
else
$strHtml.="<a href=# onclick='showHint(starttime.value,endtime.value,"
.$i.",pagesize.value)'>[".$i."]</a>";
}//end for
else
for($i=$bpage;$i<=$all_pages;$i++){
if ($nowpage==$i)
$strHtml.="<span>$i</span>";
else
$strHtml.="<a href=# onclick='showHint(starttime.value,endtime.value,"
.$i.",pagesize.value)'>[".$i."]</a>";
}//end for
}
if($nowpage!=$all_pages)
$strHtml.="<a href=# onclick='showHint(starttime.value,endtime.value,"
.($nowpage+1).",pagesize.value)'> 下一页</a>
<a href=# onclick='showHint(starttime.value,endtime.value,"
.$all_pages.",pagesize.value)'>尾页</a>";
$strHtml.=" 转到第 <select name='topage' size='+1' onchange=
'showHint(starttime.value,endtime.value,this.value,pagesize.value)'>/n";
for($i=1;$i<=$all_pages;$i++){
if($i==$nowpage){
$strHtml.="<option value='$nowpage' selected>$nowpage</option>/n";}
else
$strHtml.="<option value='$i'>$i</option>/n";
}
$strHtml.="</select> 页 ";
$strHtml.='</font></td></tr></table>';
return $strHtml;
}//end if all_pages
}//end eles1
}//end function
$db = ADONewConnection("oci8");
$db->connectSID = true;
$flag = $db->Connect("192.168.*.*","user","password","sid");
$tablesql = "select f.day day,ap,f107 from t_swpc_ap_1d a, t_swpc_f107_1d f where f.day = a.day and
f.day between '".$starttime."' and '".$endtime."'";
$sql="select * from (select A.*,rownum RN from (".$tablesql.") A where rownum <= $nowpage*$pagesize)where RN >($nowpage-1)*$pagesize ";
$rs = $db->Execute($sql);
$num=($nowpage -1) * $pagesize +1; //序号
$response = "<table cellspacing=0 bordercolordark=#FFFFFF width='100%' bordercolorlight=#000000 border=1 align='center'>
<tr bgcolor='#6b8ba8' style='color:FFFFFF'><td width='20%' align='center'>日期</td><td width='30%' align='center' >AP</td><td width='30%' align='center'>F107</td><td width='20%' align='center'>详情</td></tr>";
while(!$rs->EOF){
$response = "".$response."<tr><td width='20%'>".$rs->fields[0]."</td>".
"<td width='30%'>".$rs->fields[1]."</td>"."<td width='30%'>"
.$rs->fields[2]."</td><td width='20%' align='center'><a href=#>查看</a><td></tr>";
$num ++;
$rs->MoveNext();
}
$sql_count = "select count(*) from t_swpc_ap_1d a, t_swpc_f107_1d f where f.day = a.day and
f.day between '".$starttime."' and '".$endtime."' order by f.day asc";
$result = $db->Execute($sql_count);
$recordcount = $result->fields[0];
$response.=pageination($recordcount,2,$pagesize,$nowpage);
$db->close();
$response = $response."</table>";
echo $response;
?>
三:js文件(ajax.js)
var xmlHttp=null;
function showHint(startTime,endTime,nowpage,pagesize)
{
if (startTime>endTime)
{
document.getElementById("txtHint").innerHTML="<br><br><br>开始时间大于结束时间!"
return
}
xmlHttp=GetXmlHttpObject()
if (xmlHttp==null)
{
alert ("Browser does not support HTTP Request")
return
}
var url="getData.php"
url=url+"?starttime="+startTime+"&endtime="+endTime+"&nowpage="+nowpage+"&pagesize="+pagesize
url=url+"&sid="+Math.random()
xmlHttp.onreadystatechange=stateChanged
xmlHttp.open("GET",url,true)
xmlHttp.send(null)
}
function stateChanged()
{
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete")
{
document.getElementById("txtHint").innerHTML=xmlHttp.responseText
}
}
function GetXmlHttpObject()
{
var xmlHttp=null;
try
{
// Firefox, Opera 8.0+, Safari
xmlHttp=new XMLHttpRequest();
}
catch (e)
{
// Internet Explorer
try
{
xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e)
{
xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
}
}
return xmlHttp;
}