📄 search.jsp
字号:
<tr>
<td>
<table cellpadding=6 cellspacing=1 border=0 width=100%>
<tr>
<td bgcolor=<%=miscbacktwo%> align=center><font color=<%=fontcolormisc%>><b>搜索失败!</b></font></td>
</tr>
<tr>
<td bgcolor=<%=miscbackone%>>
<font color=<%=fontcolormisc%>>
<b>关于出现错误的详细原因:</b>
<ul>
<li><b><%=errorinfo%></b>
<li>您是否需要查看<a href="javascript:openScript('help.jsp',500,400)">帮助文件</a>?
</ul>
<br><br>
<center><< <a href="javascript:history.go(-1)">返回上一页</a></center>
</font>
</td>
</tr>
</table>
</td>
</tr>
</table>
<%
}
else {
if(TYPE_OF_SEARCH.equals("username_search")) {
querycount="posts where author like '%"+SEARCH_STRING+"%'";
query="select db,groupid,title,date_format(postat,'%Y年%m月%d日 %H:%i') as postat from posts where author like '%"+SEARCH_STRING+"%'";
if(NAME_SEARCH.equals("topictitle_search")) {
querycount+=" and parentid=0";
query+=" and parentid=0";
searchitem="主题";
}
else if(NAME_SEARCH.equals("post_search")) {
querycount+=" and parentid!=0";
query+=" and parentid!=0";
searchitem="回复";
}
else
searchitem="主题与回复";
}
else if(TYPE_OF_SEARCH.equals("keyword_search")) {
querycount="posts where";
query="select db,groupid,title,date_format(postat,'%Y年%m月%d日 %H:%i') as postat from posts where";
if(POST_SEARCH.equals("topictitle_search")) {
querycount+=" title like '%"+SEARCH_STRING+"%' and parentid=0";
query+=" title like '%"+SEARCH_STRING+"%' and parentid=0";
searchitem="标题";
}
else if(POST_SEARCH.equals("post_search")) {
querycount+=" content like '%"+SEARCH_STRING+"%'";
query+=" content like '%"+SEARCH_STRING+"%'";
searchitem="内容";
}
else if(POST_SEARCH.equals("both_search")) {
querycount+=" ((title like '%"+SEARCH_STRING+"%' and parentid=0) or content like '%"+SEARCH_STRING+"%')";
query+=" ((title like '%"+SEARCH_STRING+"%' and parentid=0) or content like '%"+SEARCH_STRING+"%')";
searchitem="标题与内容";
}
}
if(!FORUMS_TO_SEARCH.equals("0")) {
querycount+=" and db="+FORUMS_TO_SEARCH;
query+=" and db="+FORUMS_TO_SEARCH;
}
//分页变量定义
int e=20; //'每页显示的记录数
int totalpage=0; //'页面总数
int pages=1; //'显示的当前页面
int count=0; //'库中数据的总记录数
int from=0,to=0; //'从from篇到to篇
int p=0; //'数据库查询从p开始
//取页数
tempSTR=request.getParameter("pages");
if(tempSTR!=null && !tempSTR.equals(""))
pages=Integer.parseInt(tempSTR);
//分页预备
count=connect.getRowNum(querycount);
totalpage=((count%e==0)?(count/e):(count/e+1));
if(totalpage==0) totalpage=1;
if(pages>totalpage) pages=totalpage;
else if(pages<1) pages=1;
if(count!=0)
from=(pages-1)*e+1;
if(totalpage==pages)
to=count;
else if(count!=0)
to=from+e-1;
p= (pages-1)*e;
query+=" order by db,postat desc limit "+p+","+e;
%>
<table cellpadding=0 cellspacing=0 border=0 width=<%=tablewidth%> bgcolor=<%=tablebordercolor%> align=center>
<tr>
<td>
<table cellpadding=8 cellspacing=1 border=0 width=100%>
<tr>
<td bgcolor="<%=miscbacktwo%>" valign=middle colspan=4 align=center>
<font face="宋体" color=<%=fontcolormisc%>>
使用<b><%if(TYPE_OF_SEARCH.equals("username_search")) out.print("作者");else out.print("关键字");%></b>搜索方式,在<b><%=searchitem%></b>中搜索到 <b><%=count%></b> 个相匹配的贴子
</font>
</td>
</tr>
<tr>
<td bgcolor=<%=miscbackone%> valign=middle align=center width=45%>
<font face="宋体" color=<%=fontcolormisc%>><b>主题</b></font>
</td>
<td bgcolor=<%=miscbackone%> valign=middle align=center colspan=2>
<font face="宋体" color=<%=fontcolormisc%>><b>发表时间、位置</b></font>
</td>
<td bgcolor=<%=miscbackone%> valign=middle align=center width=20%>
<font face="宋体" color=<%=fontcolormisc%>><b>关键字匹配说明</b></font>
</td>
</tr>
<%
rs=connect.executeQuery(query);
while(rs.next()) {
db=rs.getInt(1);
topic=rs.getInt(2);
searchtitle=rs.getString(3);
postat=rs.getString(4);
if(db!=0) {
rs2=connect.executeQuery2("select dbname from db where id="+db);
if(rs2.next())
dbname=rs2.getString(1);
}
%>
<tr>
<td bgcolor=<%=miscbackone%> valign=middle>
<font face="宋体" color=<%=fontcolormisc%>><B><a href="topic.jsp?db=<%=db%>&topic=<%=topic%>"><%=searchtitle%></a></B><br></font>
</td>
<td bgcolor=<%=miscbackone%> valign=middle colspan=2>
<font face="宋体" color=<%=fontcolormisc%>>所处论坛: <a href="db.jsp?db=<%=db%>"><%=dbname%></a><BR>发表时间: <%=postat%></font>
</td>
<td bgcolor=<%=miscbackone%> valign=middle align=center>
<font face="宋体" color=<%=fontcolormisc%>><%if(TYPE_OF_SEARCH.equals("keyword_search")) out.print("找到关键字");else out.print("主题作者");%>: <B><%=SEARCH_STRING%></B></font>
</td>
</tr>
<%
}
%>
<form name=changepages>
<tr>
<td bgcolor="<%=miscbacktwo%>" valign=middle align=center>
<font color=<%=menufontcolor%>>
共<b><%=totalpage%></b>页
当前第<b><%out.print(from+"-"+to);%></b>个
第<b><%=pages%></b>页
</font>
</td>
<td bgcolor="<%=miscbacktwo%>">
<%
if(totalpage!=1) {
%>
<A href=search.jsp?action=<%=action%>&SEARCH_STRING=<%=SEARCH_STRING%>&TYPE_OF_SEARCH=<%=TYPE_OF_SEARCH%>&NAME_SEARCH=<%=NAME_SEARCH%>&POST_SEARCH=<%=POST_SEARCH%>&FORUMS_TO_SEARCH=<%=FORUMS_TO_SEARCH%>&pages=1><IMG alt=首页 border=0 src=images/first.gif width=11 height=10></A>
<A href=search.jsp?action=<%=action%>&SEARCH_STRING=<%=SEARCH_STRING%>&TYPE_OF_SEARCH=<%=TYPE_OF_SEARCH%>&NAME_SEARCH=<%=NAME_SEARCH%>&POST_SEARCH=<%=POST_SEARCH%>&FORUMS_TO_SEARCH=<%=FORUMS_TO_SEARCH%>&pages=<%=(pages<2)?pages:(pages-1)%>><IMG alt=上一页 border=0 src=images/previous.gif width=11 height=10></A>
<A href=search.jsp?action=<%=action%>&SEARCH_STRING=<%=SEARCH_STRING%>&TYPE_OF_SEARCH=<%=TYPE_OF_SEARCH%>&NAME_SEARCH=<%=NAME_SEARCH%>&POST_SEARCH=<%=POST_SEARCH%>&FORUMS_TO_SEARCH=<%=FORUMS_TO_SEARCH%>&pages=<%=(pages>totalpage-1)?totalpage:(pages+1)%>><IMG alt=下一页 border=0 src=images/next.gif width=11 height=10></A>
<A href=search.jsp?action=<%=action%>&SEARCH_STRING=<%=SEARCH_STRING%>&TYPE_OF_SEARCH=<%=TYPE_OF_SEARCH%>&NAME_SEARCH=<%=NAME_SEARCH%>&POST_SEARCH=<%=POST_SEARCH%>&FORUMS_TO_SEARCH=<%=FORUMS_TO_SEARCH%>&pages=<%=totalpage%>><IMG alt=末页 border=0 src=images/last.gif width=11 height=10></A>
<%
}
%>
</td>
<td bgcolor="<%=miscbacktwo%>">
<%
if(totalpage!=1) {
%>
转到:
<SELECT name=pages size=1 onchange="changePages()">
<%
for(int i=1;i<=totalpage;i++) {
if(i==pages) {
out.println("<OPTION value='search.jsp?action="+action+"&SEARCH_STRING="+SEARCH_STRING+"&TYPE_OF_SEARCH="+TYPE_OF_SEARCH+"&NAME_SEARCH="+NAME_SEARCH+"&POST_SEARCH="+POST_SEARCH+"&FORUMS_TO_SEARCH="+FORUMS_TO_SEARCH+"&pages="+i+"' selected>第"+i+"页</OPTION>");
}
else
out.println("<OPTION value='search.jsp?action="+action+"&SEARCH_STRING="+SEARCH_STRING+"&TYPE_OF_SEARCH="+TYPE_OF_SEARCH+"&NAME_SEARCH="+NAME_SEARCH+"&POST_SEARCH="+POST_SEARCH+"&FORUMS_TO_SEARCH="+FORUMS_TO_SEARCH+"&pages="+i+"'>第"+i+"页</OPTION>");
}
%>
</SELECT>
<%
}
%>
</td>
<td bgcolor="<%=miscbacktwo%>" align=center>
<font face="宋体" color=<%=fontcolormisc%>><a href="search.jsp"><b>>> 再 次 搜 索 <<</b></a></font>
</td>
</tr>
</form>
</table>
</td>
</tr>
</table>
<%
}
}
%>
<%@ include file="include/foot.jsp"%>
<%
rs.close();
connect.close();
%>
</body>
</html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -