jrthor2
07-18-2003, 07:38 AM
I have a schedules page on my site, that when a user selects a certain schedule, it displays that schedule. How would I change my code below to allow it there is no category selected, it would show all the categories each in its own table?
An example of how I want it to look is here Example (http://www.zluth.org/schedules/) . I have this working, but I have 7 different select statements on the page, and thought it might be better to use just 1 if possible.
My Code:
<%
Dim rs
Dim conn
Dim SQLstmt
Dim DSNtemp
Set conn = server.createobject("adodb.connection")
DSNtemp="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/db/schedules.mdb")
conn.Open DSNtemp
today = Month(Date) & "/" & Day(Date) & "/" & Year(Date)
cat_show = Request.QueryString("category")
If (cat_show) <> "" Then
SQLstmt = "SELECT * from Schedules where CATEGORY = '" & cat_show & "' and begin_dte <= #" & today & "# and end_dte >= #" & today & "# order by begin_dte desc, [time] desc"
Else
SQLstmt = "SELECT * from Schedules where begin_dte <= #" & today & "# and end_dte >= #" & today & "# order by begin_dte desc, [time] desc"
End If
'Response.Write(SQLstmt)
Set rs = conn.execute(SQLstmt)
%>
<html>
<head>
<title>Zion Evangelical Lutheran Church - Schedules</title>
<!--#include virtual="/inc/head_include.asp"-->
</head>
<body <% Response.Write(bodytag) %>>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td rowspan="2" valign="top">
<!--#include virtual="/inc/Menu.asp"-->
</td>
<td width="100%" valign="top">
<!--#include virtual="/inc/layout_top.asp"-->
</td>
</tr>
<tr>
<td width="100%" valign="top" height="450">
<% if NOT rs.EOF Then %>
<TABLE width="70%" cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TD noWrap bgColor=330099 height=15 rowSpan=2>
<FONT face=verdana
color=white size=-2> <B><%=cat_show%> Schedule</B></FONT></TD>
<TD height="15" vAlign=top><IMG height=15 alt=""
src="/images/tr14x15_1.gif" width=14></TD>
</TR>
</TBODY>
</TABLE>
<table width="100%" border="1" cellspacing="0" cellpadding="5" bordercolor="330099" bgcolor="#FFFFFF">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0" align="center" width="100%">
<tr>
<td width="33%"><u><strong>Date</strong></u></td>
<td width="33%"><u><strong>Time</strong></u></td>
<td width="33%"><u><strong>Name</strong></u></td>
</tr>
<%
x=0
Dim iRecordCount,mycolor
iRecordCount = 0
mycolor = "#ffffff"
Do while NOT rs.EOF
If mycolor = "#ffffff" Then
mycolor = "#d7d7ff"
Else
mycolor = "#ffffff"
End If
id = rs("ID")
begin_dte = rs("BEGIN_DTE")
end_dte = rs("END_DTE")
schedule_dte = rs("SCHEDULE_DTE")
category = rs("CATEGORY")
strtime = rs("TIME")
strname = rs("NAME")
%>
<tr bgcolor="<%=mycolor%>">
<td valign="top">
<%
Response.Write kaos_date("%N %d%s, %Y", schedule_dte)
%>
</td>
<td valign="top"><%=strtime%></td>
<td valign="top"><%=strname%></td>
</tr>
<%
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set conn = Nothing
Set SQLstmt = Nothing
Else
Response.Write ("No " & category & " Schedules available")
%>
<% End if %>
</table>
</td>
</tr>
</table>
<br>
</td>
</tr>
</table>
<tr>
<td colspan="2">
<!--#include virtual="/inc/layout_bottom.htm"-->
</td>
</tr>
</body>
</html>
An example of how I want it to look is here Example (http://www.zluth.org/schedules/) . I have this working, but I have 7 different select statements on the page, and thought it might be better to use just 1 if possible.
My Code:
<%
Dim rs
Dim conn
Dim SQLstmt
Dim DSNtemp
Set conn = server.createobject("adodb.connection")
DSNtemp="Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & Server.MapPath("/db/schedules.mdb")
conn.Open DSNtemp
today = Month(Date) & "/" & Day(Date) & "/" & Year(Date)
cat_show = Request.QueryString("category")
If (cat_show) <> "" Then
SQLstmt = "SELECT * from Schedules where CATEGORY = '" & cat_show & "' and begin_dte <= #" & today & "# and end_dte >= #" & today & "# order by begin_dte desc, [time] desc"
Else
SQLstmt = "SELECT * from Schedules where begin_dte <= #" & today & "# and end_dte >= #" & today & "# order by begin_dte desc, [time] desc"
End If
'Response.Write(SQLstmt)
Set rs = conn.execute(SQLstmt)
%>
<html>
<head>
<title>Zion Evangelical Lutheran Church - Schedules</title>
<!--#include virtual="/inc/head_include.asp"-->
</head>
<body <% Response.Write(bodytag) %>>
<table width="100%" border="0" cellspacing="0" cellpadding="2">
<tr>
<td rowspan="2" valign="top">
<!--#include virtual="/inc/Menu.asp"-->
</td>
<td width="100%" valign="top">
<!--#include virtual="/inc/layout_top.asp"-->
</td>
</tr>
<tr>
<td width="100%" valign="top" height="450">
<% if NOT rs.EOF Then %>
<TABLE width="70%" cellSpacing=0 cellPadding=0 border=0>
<TBODY>
<TD noWrap bgColor=330099 height=15 rowSpan=2>
<FONT face=verdana
color=white size=-2> <B><%=cat_show%> Schedule</B></FONT></TD>
<TD height="15" vAlign=top><IMG height=15 alt=""
src="/images/tr14x15_1.gif" width=14></TD>
</TR>
</TBODY>
</TABLE>
<table width="100%" border="1" cellspacing="0" cellpadding="5" bordercolor="330099" bgcolor="#FFFFFF">
<tr>
<td>
<table border="0" cellspacing="0" cellpadding="0" align="center" width="100%">
<tr>
<td width="33%"><u><strong>Date</strong></u></td>
<td width="33%"><u><strong>Time</strong></u></td>
<td width="33%"><u><strong>Name</strong></u></td>
</tr>
<%
x=0
Dim iRecordCount,mycolor
iRecordCount = 0
mycolor = "#ffffff"
Do while NOT rs.EOF
If mycolor = "#ffffff" Then
mycolor = "#d7d7ff"
Else
mycolor = "#ffffff"
End If
id = rs("ID")
begin_dte = rs("BEGIN_DTE")
end_dte = rs("END_DTE")
schedule_dte = rs("SCHEDULE_DTE")
category = rs("CATEGORY")
strtime = rs("TIME")
strname = rs("NAME")
%>
<tr bgcolor="<%=mycolor%>">
<td valign="top">
<%
Response.Write kaos_date("%N %d%s, %Y", schedule_dte)
%>
</td>
<td valign="top"><%=strtime%></td>
<td valign="top"><%=strname%></td>
</tr>
<%
rs.MoveNext
Loop
rs.Close
Set rs = Nothing
Set conn = Nothing
Set SQLstmt = Nothing
Else
Response.Write ("No " & category & " Schedules available")
%>
<% End if %>
</table>
</td>
</tr>
</table>
<br>
</td>
</tr>
</table>
<tr>
<td colspan="2">
<!--#include virtual="/inc/layout_bottom.htm"-->
</td>
</tr>
</body>
</html>