Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

ASP.NET Forum


You are currently viewing our ASP.NET Forum as a guest. Please register to participate.
Login



Reply
VERY NEW TO ASP! Query by Selected Date and Display Results
Old 05-31-2006, 06:56 PM VERY NEW TO ASP! Query by Selected Date and Display Results
Average Talker

Posts: 25
Trades: 0
Hi All,

I have an ASP schedule page which displays all records that are
scheduled for today's date.
I have written a drop-down list which allows selection of another
date, but I am totally stuck on how to display the records for the
new date selection.
I've messed around with code, but keep getting error messages, so
have reverted back to the original code which displays current date
records and drop-down date selection list.

If anyone could gently guide me on the code to process the query to
display the new selected date within the same page, I would be
eternally grateful!......


(Sorry for the very lengthy code, but didn't want to miss anything out!)



<%@Language=_vbscript LCID=2057%>
<!-- #Include file = "ADOVBS.INC" -->

<%
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/inetpub/wwwroot/change control.mdb"
set rs=Server.CreateObject("ADODB.recordset")
' Set SQL statement
strSQL = "SELECT * FROM tblform WHERE DATE=NOW ORDER BY DATE ASC,
START ASC"

' Open Recordset Object
rs.Open strSQL,conn
%>
<%
datToday = Date()
showDay = Request.QueryString("day")
If showDay = 0 Then
showDay = Day(datToday)
End If
showMonth = Request.QueryString("month")
If showMonth = 0 Then
showMonth = Month(datToday)
End If
showYear = Request.QueryString("year")
If showYear = 0 Then
showYear = Year(datToday)
End If
%>
<HTML>
<HEAD><TITLE>CCF Schedule</TITLE></HEAD>

<CENTER>
<H2>
Date shown: <% Response.Write FormatDateTime(Date, vbShortDate) %>
</H2>
Select Another Date:
<FORM NAME="show_date">
<SELECT NAME="day">
<% For i = 1 to 31 %>
<% If i = Day(datToday) Then %>
<OPTION VALUE="<% = i %>" SELECTED><% = i %>
<% Else %>
<OPTION VALUE="<% = i %>"><% = i %>
<% End If %>
<% Next %>
</SELECT>
<SELECT NAME="month">
<% For i = 1 to 12 %>
<% If i = Month(datToday) Then %>
<OPTION VALUE="<% = i %>" SELECTED><% = MonthName(i) %>
<% Else %>
<OPTION VALUE="<% = i %>"><% = MonthName(i) %>
<% End If %>
<% Next %>
</SELECT>
<SELECT NAME="year">
<% For i = Year(datToday) to Year(datToday) + 5 %>
<% If i = Year(datToday) Then %>
<OPTION VALUE="<% = i %>" SELECTED><% = i %>
<% Else %>
<OPTION VALUE="<% = i %>"><% = i %>
<% End If %>
<% Next %>
</SELECT>
<INPUT TYPE=submit VALUE="Select">
</FORM>

<%

' Build a table here
Response.Write("<TABLE CELLSPACING=2 CELLPADDING=0 COLS=3 WIDTH=800
BGCOLOR=#F0F0FF>")
Response.Write("<TR>")
Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15%
BGCOLOR=#000080><B>CCF</B></TD>")
Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15%
BGCOLOR=#000080><B>Type</B></TD>")
Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15%
BGCOLOR=#000080><B>Date</B></TD>")
Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15%
BGCOLOR=#000080><B>Start</B></TD>")
Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=65%
BGCOLOR=#000080><B>Summary</B></TD>")
Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15%
BGCOLOR=#000080><B>Risk</B></TD>")
Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=20%
BGCOLOR=#000080><B>Area</B></TD>")
Response.Write("</TR>")

Do While Not rs.EOF
Response.Write("<TR>")
Response.Write("<TD><a href=http://mail.yahoo.com/config/login?/""choose.asp?qryid=" &RS("CCF") & """>"
& RS("CCF") & "</a></TD>")
Response.Write("<TD>" & rs("Type") & "</TD>")
Response.Write("<TD>" & rs("Date") & "</TD>")
Response.Write("<TD>" & rs("Start") & "</TD>")
Response.Write("<TD>" & rs("Summary") & "</TD>")
Response.Write("<TD>" & rs("Risks") & "</TD>")
Response.Write("<TD>" & rs("Area") & "</TD>")
Response.Write("</TR>")
rs.MoveNext
Loop

rs.Close

Response.Write("</TABLE>")


Set rs=Nothing
conn.Close
Set conn=Nothing
%>

Last edited by devine; 05-31-2006 at 06:58 PM..
devine is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 06-01-2006, 02:28 AM Re: VERY NEW TO ASP! Query by Selected Date and Display Results
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
Juggle it around a bit.
Code:
<%
datToday = Date()
showDay = Request.QueryString("day")
If showDay = 0 Then
showDay = Day(datToday)
End If
showMonth = Request.QueryString("month")
If showMonth = 0 Then
showMonth = Month(datToday)
End If
showYear = Request.QueryString("year")
If showYear = 0 Then
showYear = Year(datToday)
End If
searchDate = showMonth & "/" & showDay & "/" & showYear 
 
' Depending on your server configuration...usually if you're in Europe...day and month may have to be reversed.

set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/inetpub/wwwroot/change control.mdb"
set rs=Server.CreateObject("ADODB.recordset")
' Set SQL statement
strSQL = "SELECT * FROM tblform WHERE [DATE]=#" & searchDate & "# ORDER BY DATE ASC, 
START ASC"

' Open Recordset Object
rs.Open strSQL,conn
%>
You should also look at your naming conventions (but in your defense, you're still a newcomer so you'll learn this as you go along.) Try not to name your fields or variables reserved words such as Date, Now, if (don't laugh, ASP expert-types...I've actually seen a guy who tried to name a variable "if" once), etc.

When I have files and fields containing more than one word, I try to use underscore characters (e.g. First_Name, Address_1, Postal_Zip, etc.) If you have people that are laymen looking at your database, you'll thank me for giving you that tip: it'll save you HOURS of trying to explain what fname, lname, addr1 are.

Mind you, that's not overly common and I can accept people's logic behind using the other way as well.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-01-2006, 05:39 AM Re: VERY NEW TO ASP! Query by Selected Date and Display Results
Average Talker

Posts: 25
Trades: 0
Adam,
Many thanks!!
With a little juggling, it does now work.
But one further minor problem....

It will display my records for selected dates 13 March 06 and 16 March 06, but will not return any records when 10 April 06 or 10 May 06 have been selected (Test database contains records for 13/06/06, 16/03/06, 10/04/06, 10/05/06 UK date format)
Is it possible that it can recognise days 13 & 16 as they can't be confused with a month number, but thinks that 10th April is in fact 4th October.....actually I have just tested this after writing it and this does seem to be the case!)

Is there anyway to correct this?
Strangely enough, the address bar is showing: http://127.0.0.1/schedule2.asp?day=4&month=10&year=2006, but after selecting 4th October, to display the record from 10th April.
But it processes 13th March correctly, with address bar as: http://127.0.0.1/schedule2.asp?day=13&month=3&year=2006

New amended code is as follows:

Code:
 
<%@Language=vbscript LCID=2057%>
<!-- #Include file = "ADOVBS.INC" -->
<%
datToday = Date()
showDay = Request.QueryString("day")
If showDay = 0 Then
showDay = Day(datToday)
End If
showMonth = Request.QueryString("month")
If showMonth = 0 Then
showMonth = Month(datToday)
End If
showYear = Request.QueryString("year")
If showYear = 0 Then
showYear = Year(datToday)
End If
searchDate = showDay & "/" & showMonth & "/" & showYear 
 
' Depending on your server configuration...usually if you're in Europe...day and month may 
have to be reversed.
set conn=Server.CreateObject("ADODB.Connection")
conn.Provider="Microsoft.Jet.OLEDB.4.0"
conn.Open "c:/inetpub/wwwroot/change control.mdb"
set rs=Server.CreateObject("ADODB.recordset")
' Set SQL statement
strSQL = ("SELECT * FROM tblform WHERE tblform.DATE=#" & showDay & "/" & showMonth & "/" & 
showYear & "# ORDER BY START ASC" )
 
' Open Recordset Object
rs.Open strSQL,conn
%>
<HTML>
<HEAD><TITLE>CCF Schedule</TITLE></HEAD>
 
<BODY>
<CENTER>
<H2>
Date shown: <% = showDay & " " & MonthName(showMonth) & " " & showYear%>
</H2>
Select Another Date: 
<FORM NAME="show_date">
<SELECT NAME="day">
<% For i = 1 to 31 %>
<% If i = Day(datToday) Then %>
<OPTION VALUE="<% = i %>" SELECTED><% = i %>
<% Else %>
<OPTION VALUE="<% = i %>"><% = i %>
<% End If %>
<% Next %>
</SELECT>
<SELECT NAME="month">
<% For i = 1 to 12 %>
<% If i = Month(datToday) Then %>
<OPTION VALUE="<% = i %>" SELECTED><% = MonthName(i) %>
<% Else %>
<OPTION VALUE="<% = i %>"><% = MonthName(i) %>
<% End If %>
<% Next %>
</SELECT>
<SELECT NAME="year">
<% For i = Year(datToday) to Year(datToday) + 5 %>
<% If i = Year(datToday) Then %>
<OPTION VALUE="<% = i %>" SELECTED><% = i %>
<% Else %>
<OPTION VALUE="<% = i %>"><% = i %>
<% End If %>
<% Next %>
</SELECT>
<INPUT TYPE=submit VALUE="Select">
</FORM>
 
<%
 
 ' Build a table here
 Response.Write("<TABLE CELLSPACING=2 CELLPADDING=0 COLS=3 WIDTH=800 BGCOLOR=#F0F0FF>")
 Response.Write("<TR>")
 Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15% BGCOLOR=#000080><B>CCF</B></TD>")
 Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15% BGCOLOR=#000080><B>Type</B></TD>")
 Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15% BGCOLOR=#000080><B>Date</B></TD>")
 Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15% BGCOLOR=#000080><B>Start</B></TD>")
 Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=65% BGCOLOR=#000080><B>Summary</B></TD>")
 Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=15% BGCOLOR=#000080><B>Risk</B></TD>")
 Response.Write("<TD ALIGN=CENTER VALIGN=TOP WIDTH=20% BGCOLOR=#000080><B>Area</B></TD>")
 Response.Write("</TR>")
 
 Do While Not rs.EOF
  Response.Write("<TR>")
  Response.Write("<TD><a href=""choose.asp?qryid=" &RS("CCF") & """>" & RS("CCF") & 
"</a></TD>")
  Response.Write("<TD>" & rs("Type") & "</TD>")
  Response.Write("<TD>" & rs("Date") & "</TD>")
  Response.Write("<TD>" & rs("Start") & "</TD>")
  Response.Write("<TD>" & rs("Summary") & "</TD>")
  Response.Write("<TD>" & rs("Risks") & "</TD>")
  Response.Write("<TD>" & rs("Area") & "</TD>")
  Response.Write("</TR>")   
  rs.MoveNext
 Loop
 
 rs.Close
 
 Response.Write("</TABLE>")
 
 
Set rs=Nothing
conn.Close
Set conn=Nothing
%>
Thanks in advance for any help you may be able to provide!
devine is offline
Reply With Quote
View Public Profile
 
Old 06-01-2006, 12:00 PM Re: VERY NEW TO ASP! Query by Selected Date and Display Results
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
I think I have the day and month reversed for this variable:

searchDate = showDay & "/" & showMonth & "/" & showYear

Try:

searchDate = showMonth & "/" & showDay & "/" & showYear

And see how that works.

Never be afraid to play with anything. It won't bite ya.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Old 06-07-2006, 03:29 PM Re: VERY NEW TO ASP! Query by Selected Date and Display Results
Average Talker

Posts: 25
Trades: 0
Hi Adam,
Your suggestion of transposing day & month has worked!
I've tested several different variations and it returns the correct results everytime!
Many Thanks,
Lynn
devine is offline
Reply With Quote
View Public Profile
 
Old 06-07-2006, 03:40 PM Re: VERY NEW TO ASP! Query by Selected Date and Display Results
ADAM Web Design's Avatar
Canadastaninianite

Posts: 5,938
Name: Adam for web page design, not program
Location: Toronto, Ontario, Canada
Trades: 0
You're most welcome!
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
(my blog)


Please login or register to view this content. Registration is FREE
(with proof)
ADAM Web Design is offline
Reply With Quote
View Public Profile Visit ADAM Web Design's homepage!
 
Reply     « Reply to VERY NEW TO ASP! Query by Selected Date and Display Results
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.23949 seconds with 12 queries