21,886
社区成员
发帖
与我相关
我的任务
分享
<?php
$q = $_REQUEST['q'];
$user = $_REQUEST['user'];
$type = $_REQUEST['type'];
$dsn = 'sqlite:ip.db';
try{
$dbh = new PDO($dsn, $user, $password);
$dbh->beginTransaction();
if (!empty($q)) {
if ($type == 'ip') {
$sth = $dbh->prepare("SELECT message FROM eimmessage WHERE recvid LIKE '%$user%' and msgtime LIKE '%$q%' order by msgtime");
$sth->execute();
$result = $sth->fetchall();
print_r($result);
$dsn=null;
}
}
}
catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
$dsn = null;
}
?>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>搜索</title>
<link href="ip.css" rel="stylesheet" type="text/css" />
</head>
<body>
<center><div class="area">
<form action="?" method="post" name="form1" target="_self" id="form1">
<label>Time:</label>
<input type="text" name="q" id="q" />
<input type="submit" name="submit" id="submit" value="Check" />
<input name="type" type="hidden" value="ip" />
<input name="user" type="hidden" id="user" value="<?php echo $user?>" />
</form></center>
</div>
</html>
<?php
$q = $_REQUEST['q'];
$user = $_REQUEST['user'];
$type = $_REQUEST['type'];
$sendid = $_REQUEST['sendid'];
$dsn = 'sqlite:ip.db';
try{
$dbh = new PDO($dsn, $user, $password);
$dbh->beginTransaction();
if (!empty($q)) {
if ($type == 'ip') {
$sth = $dbh->prepare("SELECT message,msgtime,sendid FROM eimmessage WHERE recvid LIKE '%$user%' and msgtime LIKE '%$q%' order by msgtime");
$sth->execute();
$result = $sth->fetchall();
print_r($result);
$dsn=null;
} elseif ($type == 'area') {
$sth = $dbh->prepare("SELECT message,msgtime,sendid FROM eimmessage WHERE recvid LIKE '%$user%' and sendid LIKE '%$q%' order by msgtime");
$sth->execute();
$result = $sth->fetchAll();
print_r($result);
$dsn=null;
}
}
}
catch (PDOException $e)
{
echo 'Connection failed: ' . $e->getMessage();
$dsn = null;
}
?>
function _setPage($baseUrl, $total, $start, $limit, $parm="")
{
if($total != 0) $pages = $total/$limit; else $pages = 0;
if(empty($start)) $start=0;
if(empty($limit)) $limit=20;
if($start>$total)$start=$total-$limit;
if($start<0) $start=0;
if($limit<0) $limit=0;
if($limit>100) $limit=100;
//$start = $start - $top;
$showpage = 10;
$currentpage=$start/$limit;
if($currentpage<5){
$pageno=0;
$i=0;
} else{
if($currentpage+10 > $total/$limit ){
$pageno=$currentpage -5;
}else{
$pageno=$currentpage - 5;
}
$i=$pageno*$limit;
}
if($total==0) $currentpage = -1;
$strPage = "总[" . ($currentpage + 1) . "/" . ceil($pages) . "]页 ";
$page=0;
$strPage .= "";
if($start/$limit > $showpage)
{
$tmp = ($pageno - 1)* $limit;
$strPage.= "<a href='$baseUrl&$parm&start=".($tmp)."&limit=$limit'><<</a>";
}
while($i < $total)
{
if($start/$limit ==$pageno)
{
$strPage .= "<font color=red>". ($pageno + 1) ." </font>";
}
else
{
$strPage .= "<a href='$baseUrl&$parm&start=".($pageno*$limit)."&limit=$limit'>".($pageno + 1)."</a> ";
}
$pageno++;
$page++;
$i+=$limit;
if($page > $showpage)
{
$strPage.= "<a href='$baseUrl&$parm&start=".($pageno*$limit)."&limit=$limit'>>></a>";
break;
}
}
if($start>0){
$strPage .= " <a href='$baseUrl?$parm&start=0&limit=$limit'>首页</a> ";
}else{
$strPage .= " 首页 ";
}
if($start>0){
$strPage .= " <a href='$baseUrl&$parm&start=".($start-$limit)."&limit=$limit'>上一页</a> ";
}
if($start+$limit< $total){
$strPage .= " <a href='$baseUrl&$parm&start=".($start+$limit)."&limit=$limit' >下一页</a> ";
}
if($start+$limit< $total){
$strPage .= " <a href='$baseUrl&$parm&start=".($total- $total%$limit)."&limit=$limit'>尾页</a> ";
}else{
$strPage .= " 尾页 ";
}
return $strPage;
}