按日期顺序ASP数据

时间:2014-04-24 21:13:43

标签: database asp-classic

您好,感谢您的帮助,

我有一个.asp页面,其中我有一个重复区域,列出最近的条目,我有一个提交按钮,旁边有一个下拉菜单,他们可以点击一下按日期过滤条目。但是,我不确定如何过滤这些条目。对于该特定条目,日期以mm / dd / yyyy格式传递。下拉菜单的价值是什么样的?我的代码如下:

<%@LANGUAGE="VBSCRIPT" CODEPAGE="1252"%>
<!--#include file="Connections/TTTCon.asp" -->
<%
Dim rsCall
Dim rsCall_cmd
Dim rsCall_numRows

Set rsCall_cmd = Server.CreateObject ("ADODB.Command")
rsCall_cmd.ActiveConnection = MM_TTTCon_STRING
rsCall_cmd.CommandText = "SELECT * FROM tttCalls ORDER BY theDate ASC" 
rsCall_cmd.Prepared = true

Set rsCall = rsCall_cmd.Execute
rsCall_numRows = 0
%>
<%
Dim rsDate
Dim rsDate_cmd
Dim rsDate_numRows

Set rsDate_cmd = Server.CreateObject ("ADODB.Command")
rsDate_cmd.ActiveConnection = MM_TTTCon_STRING
rsDate_cmd.CommandText = "SELECT * FROM tttCalls ORDER BY monthNum ASC" 
rsDate_cmd.Prepared = true

Set rsDate = rsDate_cmd.Execute
rsDate_numRows = 0
%>
<%
Dim Repeat1__numRows
Dim Repeat1__index

Repeat1__numRows = 10
Repeat1__index = 0
rsCall_numRows = rsCall_numRows + Repeat1__numRows
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Quality Call Library</title>
<link href="css/NewStyleSheet.css" rel="stylesheet" type="text/css" />
<script type="text/javascript">
function hideM() {
document.getElementById("Connect").style.visibility = "hidden"; 
document.getElementById("Customize").style.visibility = "hidden";   
document.getElementById("Close").style.visibility = "hidden";   
document.getElementById("Collections").style.visibility = "hidden"; 
document.getElementById("submit").style.visibility = "hidden";

}
function section1() {
document.getElementById("Connect").style.visibility = "hidden"; 
document.getElementById("Customize").style.visibility = "hidden";   
var step1Value = document.getElementById("Step1").value;
var step2Value = document.getElementById("Step2").value;
//document.getElementById("submit").style.visibility = "visible";
//alert(step1Value+" // "+step2Value);

if (step1Value == "Collections") {
    step2Value = "Collections";
    document.getElementById(step2Value).style.visibility = "visible";
    } else if(step2Value == "Connect"){
        document.getElementById("Connect").style.visibility = "visible";        
        document.getElementById("Customize").style.visibility = "hidden";   
    } 

}

</script>
</head>
<body onload="hideM()">
<center>
  <div class="ContentBackgnd"> <!-- Main Div Start -->

    <table width="950" border="0" cellspacing="0" cellpadding="0">
  <tr>
    <td width="12%" align="center" valign="top" class="Titles">Select Month:</td>
    <td rowspan="5" background="img/spacer_H240.png" width="1%">&nbsp;</td>
    <td colspan="3" rowspan="7" align="left" valign="top">
    <span class="Titles">Last 30 Loaded Calls</span><br />

<div id="BodyTbl">
  <% 
While ((Repeat1__numRows <> 0) AND (NOT rsCall.EOF)) 
%>
  <table width="100%" border="0" cellspacing="6" cellpadding="0" bgcolor="#CCCCCC">
    <!-- 
begin repeate
-->
    <tr>
      <td width="28%"><strong>Call Title:</strong>&nbsp; <%=(rsCall.Fields.Item("title").Value)%></td>
      <td colspan="4"><strong>Call Date:</strong>&nbsp;<%=(rsCall.Fields.Item("theDate").Value)%></td>
      </tr>
    <tr>
      <td colspan="5"><!-- <strong>Date Loaded:</strong>&nbsp;<%'=(rsLast10.Fields.Item("DateLoaded").Value)%>--></td>
      <td><strong>Listen Now:</strong>&nbsp;&nbsp;<a href="popup.asp?ID="><img src="img/Status-audio-volume-high-icon.png" width="16" height="16" border="0" /></a></td>
      </tr>
    <tr>
      <td colspan="6"><strong>Description:</strong> <%=(rsCall.Fields.Item("comments").Value)%><br /></td>
      </tr>
    <tr>
      <td colspan="6"><hr /></td>
      </tr>
    <!--end asp repeat-->
    <tr>
      <td>&nbsp;</td>
      <td width="1%">&nbsp;</td>
      <td width="8%">&nbsp;</td>
      <td width="20%">&nbsp;</td>
      <td width="3%">&nbsp;</td>
      <td>&nbsp;</td>
      </tr>
  </table>
  <% 
  Repeat1__index=Repeat1__index+1
  Repeat1__numRows=Repeat1__numRows-1
  rsCall.MoveNext()
Wend
%>
</div>

</td>
    </tr>
  <tr>
    <td align="center" valign="top"><img src="img/gryarrw.png" width="108" height="15" /></td>
    </tr>
  <tr>
    <td align="center" valign="top">
      <form id="NewForm" name="NewForm" method="get" action="Files.asp">
        <p>
          <select id="Step1" name="Step1" onchange="section1()">
            <option value="1" selected="selected">January</option>
            <option value="2">February</option>
            <option value="3">March</option>
            <option value="4">April</option>
            <option value="5">May</option>
            <option value="6">June</option>
            <option value="7">July</option>
            <option value="8">August</option>
            <option value="9">September</option>
            <option value="10">October</option>
            <option value="11">November</option>
            <option value="12">December</option>
</select>
          </p>
        <input type="submit" name="button" id="button" value="Submit" />
        </form><p></p>
    </td>

1 个答案:

答案 0 :(得分:0)

您有以下选项:

使用AJAX在下拉菜单中更改月份时加载/重新加载数据(您称之为过滤)

只需将此表单提交给自己,检索所选月份的值并将其传递给select语句。

从提供的代码中不清楚为什么你有这个部分:

 <%
 Dim rsDate
 Dim rsDate_cmd
 Dim rsDate_numRows

 Set rsDate_cmd = Server.CreateObject ("ADODB.Command")
 rsDate_cmd.ActiveConnection = MM_TTTCon_STRING
 rsDate_cmd.CommandText = "SELECT * FROM tttCalls ORDER BY monthNum ASC" 
 rsDate_cmd.Prepared = true

 Set rsDate = rsDate_cmd.Execute
 rsDate_numRows = 0
 %>

因为它在任何地方都没有使用。但是,如果您决定使用提交选项,请按以下方式更改您的代码:

 Dim rsCall, intMonthSelected,strSQL
 Dim rsCall_cmd
 Dim rsCall_numRows
 if len(Request.Form("Step1"))>0 then 
    intMonthSelected=cInt(Request.Form("Step1"))
 else
   intMonthSelected=0
 end if
 if intMonthSelected=0 then
     strSQL="SELECT * FROM tttCalls ORDER BY theDate ASC"
 else
    strSQL="SELECT * FROM tttCalls where  Month(theDate)=" & intMonthSelected & "  ORDER BY theDate ASC"
 end if
 Set rsCall_cmd = Server.CreateObject ("ADODB.Command")
 rsCall_cmd.ActiveConnection = MM_TTTCon_STRING
 rsCall_cmd.CommandText = strSQL 
 rsCall_cmd.Prepared = true

 Set rsCall = rsCall_cmd.Execute
 rsCall_numRows = 0
 %>

休息将与你拥有的相同。提交页面后,它将显示下拉列表中选择的月份记录(从1到31,具体取决于月份的长度)。如果您需要一系列日期,那将会更复杂一些。