Forums
This topic is locked
tricky question
Posted 30 Jul 2002 20:19:53
1
has voted
30 Jul 2002 20:19:53 Jeff Hansen posted:
hey guys, this is tricky one... at least for me! I have list of events that are entered into the database at the beginning of the year... they all have timestamps from creation and the date of the event is held in 3 columns - YEAR, MONTH, DAY.
I want to site to have a link on my site to go to the LAST event and also to the NEXT event... based on the TIME / DAY on the server.
Any ideas!?!
Replies
Replied 30 Jul 2002 21:20:13
30 Jul 2002 21:20:13 Owen Eastwick replied:
This would be easier to do if the Event Date was stored in one field:
To select the next Event:
SELECT * FROM Events WHERE EventDate >= Date() ORDER BY EventDate ASC
To select the last Event:
SELECT * FROM Events WHERE EventDate <= Date() ORDER BY EventDate DESC
To do it with the 3 fields:
Creat the links:
<a href="Events.asp?Type=Next">Next Event</a>
<a href="Events.asp?Type=Last">Last Event</a>
Then on the Events.asp page:
Create a recordset, just create any old recordset, dont worry about the parameters. Then in code view modify the RecordsetName.Source line as follows:
RecordsetName.Source = varSQLstring
Then above the recordset code add:
<%
If Request.QueryString("Type" = "Last" Then
varSQLstring = "SELECT * FROM Events WHERE Year <= DatePart(yyyy, Date()) AND Month <= DatePart(m, Date()) AND Day <= Datepart(d, Date()) ORDER BY Year, Month, Day DESC"
Else
varSQLstring = "SELECT * FROM Events WHERE Year >= DatePart(yyyy, Date()) AND Month >= DatePart(m, Date()) AND Day >= Datepart(d, Date()) ORDER BY Year, Month, Day ASC"
End If
%>
The page will then default to showing the next event.
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
To select the next Event:
SELECT * FROM Events WHERE EventDate >= Date() ORDER BY EventDate ASC
To select the last Event:
SELECT * FROM Events WHERE EventDate <= Date() ORDER BY EventDate DESC
To do it with the 3 fields:
Creat the links:
<a href="Events.asp?Type=Next">Next Event</a>
<a href="Events.asp?Type=Last">Last Event</a>
Then on the Events.asp page:
Create a recordset, just create any old recordset, dont worry about the parameters. Then in code view modify the RecordsetName.Source line as follows:
RecordsetName.Source = varSQLstring
Then above the recordset code add:
<%
If Request.QueryString("Type" = "Last" Then
varSQLstring = "SELECT * FROM Events WHERE Year <= DatePart(yyyy, Date()) AND Month <= DatePart(m, Date()) AND Day <= Datepart(d, Date()) ORDER BY Year, Month, Day DESC"
Else
varSQLstring = "SELECT * FROM Events WHERE Year >= DatePart(yyyy, Date()) AND Month >= DatePart(m, Date()) AND Day >= Datepart(d, Date()) ORDER BY Year, Month, Day ASC"
End If
%>
The page will then default to showing the next event.
Regards
Owen.
Multiple Parameter UD4 / Access 2000 Database Search Tutorial:
www.tdsf.co.uk/tdsfdemo
Replied 30 Jul 2002 22:17:47
30 Jul 2002 22:17:47 Jeff Hansen replied:
thanks for that input..
there is one small thing differnt i forgot to mention.. each event has a Name... i wnat to show that NAME on my default page, the name will be the link to the acutal event.
there is one small thing differnt i forgot to mention.. each event has a Name... i wnat to show that NAME on my default page, the name will be the link to the acutal event.
Replied 31 Jul 2002 23:51:13
31 Jul 2002 23:51:13 Jeff Hansen replied:
*bump*
anyone know how to do what i describe in then previous post?
anyone know how to do what i describe in then previous post?