我添加了三个单选按钮,我希望这些按钮可以对asp经典页面上显示的数据列表进行排序。数据是从数据库中提取的,下面的代码是我到目前为止已完成排序但我无法完成的。首先,我想获得一个onSelect提交选项,它将刷新页面或列表(刷新列表会更好),并根据用户选择的顺序对列表进行相应的排序。
单选按钮的代码
<form method=get action=featuredvehicle.asp>
<input type="radio" name="sort" value="make">Make<br>
<input type="radio" name="sort" value="model">Model<br>
<input type="radio" name="sort" value="model_year">Model Year
</form>
从单选按钮获取值的代码
<%
Dim strSQL1
Dim OrderList
OrderList = Request.QueryString("sort")
If OrderList = "" Then
strSQL1 = "SELECT * FROM featuredvehicles ORDER by make, model, model_year asc;"
ElseIf OrderList = make THEN
strSQL1 = "SELECT * FROM featuredvehicles ORDER by make, model, model_year asc;"
ElseIf OrderList = model THEN
strSQL1 = "SELECT * FROM featuredvehicles ORDER by model, model, model_year asc;"
rsLogbook.Open strSQL1, adoCon
ElseIf OrderList = model_year THEN
strSQL1 = "SELECT * FROM featuredvehicles ORDER by model_year, make, model asc;"
END IF
rsLogbook.Open strSQL1, adoCon
%>
从数据库列出列表的代码。
<blockquote>
<% rsLogbook.Movefirst
do while not rsLogbook.EOF %>
<p align="left" style="margin-top: 0; margin-bottom: 0"><font face="Tahoma" size="2" color="#5A87B4">
<img border="0" src="images/obdkey_icon.gif"><a href="http://websitelink.com?vehicle=<%Response.Write(rsLogbook("id"))%>">
<%=rsLogbook("make")%> <%=rsLogbook("model")%> <%=rsLogbook("model_year")%></a>
<%Response.Write("<br />") %>
<% rsLogbook.MoveNext%></font></p>
<%loop %>
</blockquote>
我想再次做的是
答案 0 :(得分:0)
我建议进行查询并列出单个代码块。连接输出子字符串和记录字段,然后用一条response.write
指令写整行。
<blockquote>
<%
Dim strSQL1
Dim OrderList
OrderList = Request.QueryString("sort")
strSQL1 = "SELECT * FROM featuredvehicles ORDER BY "
Select Case OrderList
Case "", make : strSQL1 = strSQL1 & "make, model, model_year ASC;"
Case model : strSQL1 = strSQL1 & "model, make, model_year ASC;"
Case model_year : strSQL1 = strSQL1 & "model_year, make, model ASC;"
End Select
rsLogbook.Open strSQL1, adoCon
rsLogbook.Movefirst
do while not rsLogbook.EOF
response.write "<p align=""left"" style=""margin-top: 0; margin-bottom: 0""><font face=""Tahoma"" size=""2"" color=""#5A87B42"">" _
& "<img border=""0"" src=""images/obdkey_icon.gif""><a href=""http://websitelink.com?vehicle=" & rsLogbook("id") & """>" _
& rsLogbook("make") & " " & rsLogbook("model") & " " & rsLogbook("model_year") & "</a><br /></font></p>"
rsLogbook.MoveNext</font></p>
loop
%>
</blockquote>
也就是说,如果您的数据不经常更改并且您只希望用户能够动态更改结果集的顺序,则不应对数据库运行重复查询(使用不同的{{ 1}}条款)。这会对Web服务器和数据库造成不必要的负担。
在这种情况下,最好只检索一次结果集(无序或使用默认顺序),并使用某些客户端JavaScript框架对结果进行任何后续(重新)排序(例如{{3 }})。