主题:  查询页面下拉菜单一个项对应三个字段应如何做?

万木春

职务:普通成员
等级:1
金币:0.0
发贴:165
#12005/6/15 13:16:42
我数据库有“规格型号1”,“规格型号,2”,“规格型号3”三个字段,在查询页面的下拉菜单中如设置“规格型号1”,“规格型号,2”,“规格型号3”将会很难看,因此我想用“规格型号”中来对应这三个字段,即输入查询关键字后,再点击下拉菜单中的规格型号就去三个字段查找关键字对应的记录,请问这个如何做?
<%
'设置查询条件
if Request("cif")<>"" and Request("ccif")<>"" and Request("qvalue")<>"" then
session("MMColParam") = ""
if (Request("qvalue") <> "") then session("MMColParam") = Request("qvalue")
session("varcif")= ""
if (Request("cif") <> "") then session("varcif") = Request("cif")

session("varccif") = "ALL"

if (Request("ccif") <> "") then session("varccif") = Request("ccif")
else
    if session("varccif")="" then
    session("varccif")="ALL"
    end if
end if
%>
<%
set rs = Server.CreateObject("ADODB.Recordset")
'设置查询字符串
if session("varccif") = "LIKE" then
sql ="SELECT * FROM wl WHERE "&_
Replace(session("varcif"), "'", "''") & " " & Replace(session("varccif"), "'", "''") &_
     " '%" & Replace(session("MMColParam"), "'", "''") & "%'"
else
    if session("varccif") = "ALL" then
    sql = "SELECT * FROM wl"
    else

    sql ="SELECT * FROM wl WHERE "&_
     Replace(session("varcif"), "'", "''") & " " & Replace(session("varccif"), "'", "''") &_
     " '" + Replace(session("MMColParam"), "'", "''") & "'"
     end if

end if
rs.open sql,conn,1,1


<option value="wlmodel">规格型号</option>
<option value="wlfactory">生产厂家</option>



蓝鲸

职务:版主
等级:5
金币:42.1
发贴:2614
#22005/6/16 8:57:48
你的话有点深奥


非常大鱼

万木春

职务:普通成员
等级:1
金币:0.0
发贴:165
#32005/6/17 17:26:39
发觉有二个问题:
1。查询规格型号时,如查询“联通手机”,虽然规格型号1。规格型号2中均有这条记录,但是显示的是规格型号1的记录,而我要全部条件的记录,这个应如何做呢?
2。如下代码中改动过“规格型号”字段在查询后翻页(下一页)时会不按查询关键字列出规格型号1,规格型号2。。。规格型号5的记录而是把所有数据库的内容列出,未改动过其他字段可以正常分页,请问应如何做呢?
set rs = Server.CreateObject("ADODB.Recordset")
'设置查询字符串
if session("varccif") = "LIKE" then

if session("varcif")="wlmodel" then
sql = "select * from wl where "
sql = sql & "wlmodel1 like '%" & Request("qvalue") & "%' or wlmodel2 like '%" & Request("qvalue") & "%' or wlmodel3 like '%" & Request("qvalue") & "%' or wlmodel4 like '%" & Request("qvalue") & "%' or wlmodel5 like '%" & Request("qvalue") & "%'"
else
sql ="SELECT * FROM wl WHERE "&_
Replace(session("varcif"), "'", "''") & " " & Replace(session("varccif"), "'", "''") &_
" '%" & Replace(session("MMColParam"), "'", "''") & "%'"
end if
else
if session("varccif") = "ALL" then

if session("varcif")="wlmodel" then
sql = "select * from wl where "
sql = sql & "wlmodel1 like '%" & Request("qvalue") & "%' or wlmodel2 like '%" & Request("qvalue") & "%' or wlmodel3 like '%" & Request("qvalue") & "%' or wlmodel4 like '%" & Request("qvalue") & "%' or wlmodel5 like '%" & Request("qvalue") & "%'"
else
sql = "SELECT * FROM wl"
end if

else
if session("varcif")="wlmodel" then
sql = "select * from wl where "
sql = sql & "wlmodel1='" & request.Form("qvalue") & "' or wlmodel2='"&request.Form("qvalue")&"' or wlmodel3='"&request.Form("qvalue")&"' or wlmodel4='"&request.Form("qvalue")&"' or wlmodel5='"&request.Form("qvalue")&"'"
else

sql ="SELECT * FROM wl WHERE "&_
Replace(session("varcif"), "'", "''") & " " & Replace(session("varccif"), "'", "''") &_
" '" + Replace(session("MMColParam"), "'", "''") & "'"
end if
end if
end if
rs.open sql,conn,1,1
%>
<% if page<>1 then %>
<a href=<%=path%>?page=1 class="l"> 第一页</a> <a href=<%=path%>?page=<%=(page-1)%> class="l">上一页</a>
<%end if
if page<>rs.pagecount then %>
<a href=<%=path%>?page=<%=(page+1)%> class="l">下一页</a> <a href=<%=path%>?page=<%=rs.pagecount%> class="l">最后一页</a>
<%end if %>