PDA

View Full Version : Dynamic link with Date and a Region


Ledevin
12-22-2002, 10:20 PM
First of all, let me say that I been looking for a board like for a while and that I am glad that I did find this one.

Ok, my problem is this. The user select a region (geographic) and is then taken to the region's main page, which is database driven. On the page he can view a lot of info (members, maps...). I then have a link that will direct him to a calendar of activities. When he get to the page the first time (calendar.asp) the page checks for the date and the region and writes it with a repeat region(asp).

This works, but if the user clicks on a date in the calendar, which is link to itself (calendar.asp?date=) it doesn't take the region code and it display all the events of all the regions for that date.

I try to attach a second value to the link (calendar.asp?date= &dtoday"&region=) but it doesn't work.

Any help will be great. Here is my code for the calendar. I'm using an Access Database and Ultradev.




dToday = CDate(intThisMonth & "/" & intPrintDay & "/" & intThisYear)
If NOT Rs.EOF Then

' Set events flag to false. This means the day has no event in it

bEvents = False
Do While NOT Rs.EOF AND bEvents = False

' If the date falls within the range of dates in the recordset, then
' the day has an event. Make the events flag True

If dToday >= Rs("datein") AND dToday <= Rs("dateout") Then

' Print the date in a highlighted font

Write_TD "<A HREF=events.asp?date="& Server.URLEncode(dToday) & " CLASS='EVENT' TARGET='rightframe'> " & intPrintDay & "</A>", "HL"

bEvents = True

' If the Start date is greater than the date itself, there is no point
' checking other records. Exit the loop

ElseIf dToday < Rs("datein") Then
Exit Do

' Move to the next record

Else
Rs.MoveNext
End If
Loop

' Checks for that day

Rs.MoveFirst
End If

' If the event flag is not raise for that day, print it in a plain font

If bEvents = False Then
Write_TD "<A HREF=events.asp?date="& Server.URLEncode(dToday) & " CLASS='NOEVENT' TARGET='rightframe'> " & intPrintDay & "</A>", "SOME"
End If
End If

' Increment the date. Done once in the loop.

intPrintDay = intPrintDay + 1
End If

raf
12-23-2002, 08:14 AM
If i understood it corect, you wnt to run a select query with two conditions: date and region.

You get the date from the clicked link.
The region can come from a querystring or a session-variable or ...


basic sql code

selecteddate=request.querystring("date")
region=session("region") 'in case of session variable
region=request.querystring("region") 'in case of querystring
dim rsAct
set rsAct = server.CreateObject("adodb.recordset")
sql = "SELECT variables FROM tablename WHERE date=#adate# AND region='aregion'"
sql=replace(sql,"aregion",region)
sql=replace(sql,"adate",selecteddate)

rsAct.Open sql, conectionname




All you need to do is store the region in a session-variable after the region was selected on the previous page (before you redirect to this page, you store the info in this variable. For instance like this

session("region")=request.querystring("region")

or

session("region")=request.form("region")


You see, there are a lot of possibilitys. Passing on these data is in fact the core-activity in all databasedrive applications, so it's quite important you master it.

Let us know if this gets you any further.

whammy
12-24-2002, 12:27 AM
Basically what raf said - you'll need to pass the region somehow as an argument as well, and since you're already using a querystring, you might as well pass that along too...

"whatever.asp?date=" & datevariable & "&region=" & region

If you already tried this, did you check to make sure that you were parsing the variable from the querystring?

Also, as raf said, this is just one way to pass along the data. You can use Session variables, hidden form fields which are passed from page to page using the "POST" method, or querystrings. FYI an easy way to create hidden fields with all post variables to pass along, since I'm sure you will use it at some point:


<%
Dim Item
For Each Item in Request.Form
Response.Write("<input type=""hidden"" name=""" & Item & """ value=""" & Request.Form(Item) & """ />" & vbCrLf)
Next
%>

Ledevin
12-24-2002, 06:22 PM
Thanks guys!

I didn't think of a session Var. I will try this.

The calendar code comes from a free app. But I try to put a second condition, it doesn't work. The person that made the codes put in a server encoding behavior.

------------------
Write_TD "<A HREF=events.asp?date="& Server.URLEncode(dToday) & " CLASS='EVENT' TARGET='rightframe'> " & intPrintDay & "</A>", "HL"
---------------------

And I don't know if it is going to effect my new session variable.

whammy
12-25-2002, 12:52 AM
No, that won't affect your session variable - don't be afraid to mess around with things, either, and see if they work. ;)

Server.URLEncode() just escapes characters, do a search for Server.URLEncode() on http://www.google.com and you'll see what I mean. :)

Ledevin
12-26-2002, 09:09 PM
Ok!

Thanks whammy :thumbsup: