webForumDet fria alternativet

visa fyra månader istället för 1

ASP

2 svar · 173 visningar · startad av Bosse168

Medlem sedan nov. 20031 018 inlägg
Frågan#1

Någon som kan hjälpa mig att optimera och istället för att bara visa en månad så ska den visa 4 stycken alltså April, Maj, Juni och Juli.
Är detta möjligt utan att behöva skriva ut koden 4ggr på samma sida i olika kolumner i en tabell?
Databasen jag använder är MySQL 4.0.18-nt

<%
Set RSBODY = Connect.Execute("SELECT * from kalend_settings")

navmonth = request.querystring("month")
navyear = request.querystring("year")

If navmonth = "" Then
	navmonth = Month(Date)
End If

If navyear = "" Then
	navyear = Year(Date)
End If

firstday = Weekday(CDate(navmonth & "/" & 1 & "/" & navyear))

leapTestNumbers = navyear / 4
leapTest = (leapTestNumbers) - Round(leapTestNumbers)
If navmonth = 2 Then
	If leapTest <> 0 Then
		lastDate = 28
	Else
		lastDate = 29
	End If
ElseIf ((navmonth = 4) OR (navmonth = 6) OR (navmonth = 9) OR (navmonth = 11)) Then
	lastDate = 30
Else
	lastDate = 31
End If

lastMonth = navmonth - 1
lastYear = navyear
If lastMonth < 1 Then
	lastMonth = 12
	lastYear = lastYear - 1
End If

nextMonth = navmonth + 1
nextYear = navyear
If nextMonth >12 Then
	nextMonth = 1
	nextYear = nextYear + 1
End If

dateCounter = 1
weekCount = 1

DateEnd = lastDate
DateBegin = firstDate

Weekday_Font = RSBODY("Weekday_Font")
Weekday_Font_Size = RSBODY("Weekday_Font_Size")
Weekday_Font_Color = RSBODY("Weekday_Font_Color")
Weekday_Background_Color = RSBODY("Weekday_Background_Color")
Date_Font = RSBODY("Date_Font")
Date_Font_Size = RSBODY("Date_Font_Size")
Date_Font_Color = RSBODY("Date_Font_Color")
Date_Background_Color = RSBODY("Date_Background_Color")
Event_Font = RSBODY("Event_Font")
Event_Font_Size = RSBODY("Event_Font_Size")
Event_Font_Color = RSBODY("Event_Font_Color")
Cell_Width = RSBODY("Cell_Width")
Cell_Height = RSBODY("Cell_Height")
Cell_Background_Color = RSBODY("Cell_Background_Color")
Border_Size = RSBODY("Border_Size")
Border_Color = RSBODY("Border_Color")
%>
<%=RSBODY("Header")%>

<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td align="center">

<table border="0" cellpadding="2" cellspacing="0" width="100%">
<tr>
<td align="left" valign="bottom">
<font face="verdana" size="2">

<b>
<a href="default.asp?month=<%=lastMonth%>&year=<%=lastYear%>">
<%
If (RSBODY("Abbreviate_Months") = True) Then
%>

<%=MonthName(lastMonth, true)%>
<%Else%>

<%=Ucase(Left(MonthName(lastMonth),1)) & Mid(MonthName(lastMonth),2)%>

<%End If%>

</a></b></font>

</td>

<td align="center" valign="bottom">

<font face="verdana" size="4">
<b><%If (RSBODY("Abbreviate_Months") = True) Then%>
<%=MonthName(navMonth, true)%>

<%Else%>

<%=Ucase(Left(MonthName(navMonth),1)) & Mid(MonthName(navMonth),2)%>

<%End If%>

&nbsp;
<%=navyear%></b></font>

</td>
<td align="right" valign="bottom"><font face="verdana" size="2"><b><a href="default.asp?month=<%=nextMonth%>&year=<%=nextYear%>"><%If (RSBODY("Abbreviate_Months") = True) Then%><%=MonthName(nextMonth, true)%><%Else%><%=Ucase(Left(MonthName(nextMonth),1)) & Mid(MonthName(nextMonth),2)%><%End If%></a></b></font></td>
</tr>
</table>

</td>
</tr>
<tr>
<td>

<table border="0" cellpadding="0" cellspacing="0" align="center">
<tr>
<td bgcolor="<%=Border_Color%>">

<table border="0" cellpadding="2" cellspacing="<%=Border_Size%>">
<tr>
<td width="<%=Cell_Width%>" align="center" background="../mat/bilder/rubrik.gif"><font face="<%=Weekday_Font%>" size="<%=Weekday_Font_Size%>" color="<%=Weekday_Font_Color%>"><b><%If (RSBODY("Abbreviate_Days") = True) Then%>Sön<%Else%>Söndag<%End If%></b></font></td>
<td width="<%=Cell_Width%>" align="center" background="../mat/bilder/rubrik.gif"><font face="<%=Weekday_Font%>" size="<%=Weekday_Font_Size%>" color="<%=Weekday_Font_Color%>"><b><%If (RSBODY("Abbreviate_Days") = True) Then%>Mån<%Else%>Måndag<%End If%></b></font></td>
<td width="<%=Cell_Width%>" align="center" background="../mat/bilder/rubrik.gif"><font face="<%=Weekday_Font%>" size="<%=Weekday_Font_Size%>" color="<%=Weekday_Font_Color%>"><b><%If (RSBODY("Abbreviate_Days") = True) Then%>Tis<%Else%>Tisdag<%End If%></b></font></td>
<td width="<%=Cell_Width%>" align="center" background="../mat/bilder/rubrik.gif"><font face="<%=Weekday_Font%>" size="<%=Weekday_Font_Size%>" color="<%=Weekday_Font_Color%>"><b><%If (RSBODY("Abbreviate_Days") = True) Then%>Ons<%Else%>Onsdag<%End If%></b></font></td>
<td width="<%=Cell_Width%>" align="center" background="../mat/bilder/rubrik.gif"><font face="<%=Weekday_Font%>" size="<%=Weekday_Font_Size%>" color="<%=Weekday_Font_Color%>"><b><%If (RSBODY("Abbreviate_Days") = True) Then%>Tors<%Else%>Torsdag<%End If%></b></font></td>
<td width="<%=Cell_Width%>" align="center" background="../mat/bilder/rubrik.gif"><font face="<%=Weekday_Font%>" size="<%=Weekday_Font_Size%>" color="<%=Weekday_Font_Color%>"><b><%If (RSBODY("Abbreviate_Days") = True) Then%>Fre<%Else%>Fredag<%End If%></b></font></td>
<td width="<%=Cell_Width%>" align="center" background="../mat/bilder/rubrik.gif"><font face="<%=Weekday_Font%>" size="<%=Weekday_Font_Size%>" color="<%=Weekday_Font_Color%>"><b><%If (RSBODY("Abbreviate_Days") = True) Then%>Lör<%Else%>Lördag<%End If%></b></font></td>
</tr>

<tr>
<% Do while weekCount <= 7
dateSelect = navmonth & "/" & dateCounter & "/" & navyear %>

<% If (weekCount < firstDay) OR (dateCounter > lastDate) Then %>
<td height="<%=Cell_Height%>" bgcolor="<%=Cell_Background_Color%>"><img src="../bilder/pixel.gif" height="1" width="1"></td>
<% else %>
<td height="<%=Cell_Height%>" bgcolor="<%=Date_Background_Color%>" valign="top">

<a href="datumet.asp.asp?date=<%=dateSelect%>">
<%
If weekCount="1" Then
Response.Write("<font face='"& Date_Font &"' size='"& Date_Font_Size &"' color='#FF0000'>")
Else
Response.Write("<font face='"& Date_Font &"' size='"& Date_Font_Size &"' color='"& Date_Font_Color &"'>")
End If
%>
<b><%=dateCounter%></b></font><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>">

<%
Set RSEVENT = Connect.Execute("SELECT * from kalend_events")

Do while NOT RSEVENT.EOF

rsdate = RSEVENT("Date")

If (Day(rsdate) = dateCounter) AND (Month(rsdate) = CInt(navmonth)) AND (Year(rsdate) = CInt(navyear)) Then%>

<br>
<%

If RSBODY("Event_Display") = True Then

Response.Write RSEVENT("Category")

Else

Response.Write RSEVENT("Event_Name")

End If

End If
RSEVENT.movenext
Loop
RSEVENT.close : Set RSEVENT=Nothing
%>

</font></a></td>

<% 
dateCounter = dateCounter + 1
end if

weekCount = weekCount + 1
Loop
weekCount = 1
%>
</tr>
<% Do while dateCounter <= lastDate %>
<tr>
<% Do while weekCount <= 7
dateSelect = navmonth & "/" & dateCounter & "/" & navyear %>

<% If dateCounter > lastDate Then %>
<td height="<%=Cell_Height%>" bgcolor="<%=Cell_Background_Color%>"><img src="../bilder/pixel.gif" height="1" width="1"></td>
<% else %>
<td height="<%=Cell_Height%>" bgcolor="<%=Date_Background_Color%>" valign="top">

<a href="datumet.asp?date=<%=dateSelect%>">
<%
If weekCount="1" Then
Response.Write("<font face='"& Date_Font &"' size='"& Date_Font_Size &"' color='#FF0000'>")
Else
Response.Write("<font face='"& Date_Font &"' size='"& Date_Font_Size &"' color='"& Date_Font_Color &"'>")
End If
%>

<b><%=dateCounter%></b></font><font face="<%=Event_Font%>" size="<%=Event_Font_Size%>" color="<%=Event_Font_Color%>">

<%
Set RSEVENT = Connect.Execute("SELECT * from kalend_events")
Do while NOT RSEVENT.EOF
rsdate = RSEVENT("Date")
If (Day(rsdate) = dateCounter) AND (Month(rsdate) = CInt(navmonth)) AND (Year(rsdate) = CInt(navyear)) Then%>

<br>
<%If RSBODY("Event_Display") = True Then%>
<%=RSEVENT("Category")%>
<%Else%>
<%=RSEVENT("Event_Name")%>
<% End If

End If
RSEVENT.movenext
Loop
RSEVENT.close
Set RSEVENT=Nothing
%>

</font></a></td>

<% 
dateCounter = dateCounter + 1
end if

weekCount = weekCount + 1
Loop
weekCount = 1
%>
</tr>
<% Loop %>

</table>

</td>
</tr>
</table>

</td>
</tr>
</table>
Medlem sedan juni 200032 967 inlägg
#2

Gör koden till en sub och kalla på den från de fyra olika platserna i dokumentet. Exempel på en sub:

Sub WriteMonth(intMonth)
     Response.write intMonth
End Sub

 . . . . . . . 

Response.write "<table><tr><td>"
Call WriteMonth(1)
Response.write "</td><td>"
Call WriteMonth(2)
Response.write "</td><td>"
Call WriteMonth(3)
Response.write "</td><td>"
Call WriteMonth(4)
Response.write "</td></tr></table>"
Medlem sedan nov. 20031 018 inlägg
#3

Förstår inte hur du menar. :(
Inte en aning hur man kan få in den koden i en sub.

253 ms totalt · 4 externa anrop · v20260731065814-full.a51de22e
119 ms — deklarationer (db)
0 ms — hämta statistik (cache)
130 ms — hämta tråd, inlägg och bilagor (db)
121 ms — ändringar (db)