标题:ASP+access数据库价格区段排序的问题
只看楼主
cwang2100
Rank: 2
等 级:论坛游民
帖 子:12
专家分:12
注 册:2010-3-16
结帖率:100%
 问题点数:0 回复次数:1 
ASP+access数据库价格区段排序的问题
大家好,我是菜鸟,想学一下ASP语言,请大家多多帮忙啊!!!

我的access数据库是data.mdb,表是tade,字段有五个,aa, bb,都是备注 cc,dd类型都是数字。  

id(自动编码)  aa(产品名称) bb(省份) cc(价格/斤)  dd(级别)

   1             花生       广东省   6.00元        1

   2             花生       广西省   185.00元      8

   3             花生油     广西省   58.00元       15

搜索条如下图:



我想达到的功能是1、按价格从低到高,2、按级别从低到高,3、1元-100元,4、100元-200元 5、200元-300元,现在的代码按价格从低到高和按级别从低到高都可以,就是1元-100元,100元-200元,200元-300元这些区段的语句代码不会写,望高手指点..分数不多了全给了,谢谢!!

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.
<html xmlns="http://www.
<head>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>文件</title>
</head>
<body bgcolor="#ffffff">

<table width=690 border="0" cellspacing="0" bordercolorlight="#4DA6FF" bordercolordark="#ECF5FF" width="100%"  style="word-break:break-all" align="center">
<tr>
<td width="590" align="center" colspan="7">
<form method="POST" name="form1" action=sou.asp>
<P><font style="font-size: 14px " color="0000ff" align="left">搜索内容</font>
<input type="text" name="aa" size="15" id="aa"value="<%=request("aa")%>">
<select name="bb" id="bb">
<option selected="selected" value="">所在地区</option>
    <option value="广东"  <%if Request("bb")="广东" then Response.write "selected"%>>广东</option>
        <option value="江苏"  <%if Request("bb")="江苏" then Response.write "selected"%>>江苏</option>
        
</select>
    <select name="dd" id="dd">
    <option selected="selected" value="">等级分类</option>
    <option value="4"  <%if Request("dd")="1" then Response.write "selected"%>>一级</option>
        <option value="3"  <%if Request("dd")="2" then Response.write "selected"%>>二级</option>   
    <option value="2"  <%if Request("dd")="3" then Response.write "selected"%>>三级</option>   
      
</select>
        <select name="cc" id="cc">
    <option selected="selected" value="">默认排序</option>
    <option value="251" <%if Request("cc")="251" then Response.write "selected"%>>按价格从低到高</option>
    <option value="99999991"  <%if Request("cc")="99999991" then Response.write "selected"%>>按级别从高到低</option>

    <option value="99999992"  <%if Request("cc")="99999991" then Response.write "selected"%>>按级别从低到高</option>
        <option value="250"   <%if Request("cc")="250" then Response.write "selected"%>>按价格从高到低</option>
 <option value="100"   <%if Request("cc")="100" then Response.write "selected"%>>1元-100元区</option>               <option value="100"   <%if Request("cc")="100" then Response.write "selected"%>>100元-200元区</option>              <option value="200"   <%if Request("cc")="200" then Response.write "selected"%>>200元-300元区</option>
         
</select></select><input type="submit" value="搜索" name="B1"></form>  
</tr>
</table>

<TABLE width=690 bgColor=#FFFFFF border=0 bordercolor="0" align="center">
<TR>
<TD>

<%
aa=request.form("aa")
bb=request.form("bb")
dd=request.form("dd")
cc=request.form("cc")
dim pageCount
page = cint(request("page"))
set conn=server.createobject("adodb.connection")
set rs=server.createobject("adodb.recordset")
conn.open "DBQ=" & server.mappath("data.mdb") & ";DefaultDir=;DRIVER={Microsoft Access Driver (*.mdb)};"

sql="select * from tade where 1=1 "

Dim SearchStr

if aa <> "" then
sql=sql&"and minqing like '%"&aa& "%'"
end if
if bb<>"" then
sql=sql&"and dindi like '%"&bb&"%'"
end if

if dd<>"" then

sql=sql&"and guang like '%"&dd&"%'"

end if

if cc="" then

sql=sql&"  order by id desc"

end if

if cc="251" then
sql=sql&"  order by ping asc"

end if

if cc="99999991" then
sql=sql&" order by guang desc"
end if

if cc="99999992" then
sql=sql&" order by guang asc"
end if

if cc="250" then
sql=sql&" order by ping desc"
end if

if cc="100" then
sql=sql&" order by ping between 1 and 100 desc"

end if

if cc="200" then
sql=sql&" order by ping between 100 and 200 desc"

end if

rs.open sql,conn,3,3

if rs.bof then
errmsg=errmsg+"<br>"+"<li>"+keyword+"没有该商品记录,请返回."
response.end
end if

RS.PageSize=8
pageCount = cint(rs.pageCount)

if page = 0 then
page =1
end if
RS.AbsolutePage = page
x=1

WHILE NOT RS.EOF AND NumRows<RS.PageSize
%>
<tr>
<td width="160"  >

<div align="center"><font  style="font-size: 13px">价格:</font><font style="font-size: 16px" color="#ff0000"><strong><%=rs("ping")%>元</strong></font></div>
</tr>
</td>
<tr>

</tr></div>
</table></div>

<%RS.MoveNext
NumRows=NumRows+1
WEND%>

</body></html>
<%
rs.close
Set rs=nothing
conn.close
set conn=nothing
%>
搜索更多相关主题的帖子: ASP 价格 数据库 access 区段 
2010-03-20 22:57
icecool
Rank: 9Rank: 9Rank: 9
等 级:贵宾
威 望:20
帖 子:1214
专家分:1366
注 册:2005-3-14
得分:0 
你在数据库多加一个字段,用来区分价格等级,录入数据时就进行判断,属1-100之间的,该字段内容就为:1元-100元,

这样搜索查询时不用进行处理就可很好的分类查询出来!

http://toorup.3v.do
loading...
2010-03-26 17:06



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-300044-1-1.html




关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 1.035761 second(s), 9 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved