Click to See Complete Forum and Search --> : loop query
leeny
01-26-2005, 10:06 PM
im very new to asp and frankly speaking i dun really rem how to do loop. can you guys advice me on how to perform a loop here?
<%
BaseDate13 = Month(Dateadd("M",+11,date))&"/"&Day(Dateadd("M",+11,date))&"/"&Year(Dateadd("M",+11,date))
FirstOfMonth13 = DateSerial(Year(BaseDate13), Month(BaseDate13) + iOffset, 1)
EndOfMonth13 = DateSerial(Year(BaseDate13), Month(BaseDate13) + 1, 0)
MidOfMonth13= DateSerial(Year(BaseDate13), Month(BaseDate13) + 1, -ROUND(Day(EndOfMonth13)/2)+1)
BaseDate12 = Month(Dateadd("M",+10,date))&"/"&Day(Dateadd("M",+10,date))&"/"&Year(Dateadd("M",+10,date))
FirstOfMonth12 = DateSerial(Year(BaseDate12), Month(BaseDate12) + iOffset, 1)
EndOfMonth12 = DateSerial(Year(BaseDate12), Month(BaseDate12) + 1, 0)
MidOfMonth12= DateSerial(Year(BaseDate12), Month(BaseDate12) + 1, -ROUND(Day(EndOfMonth12)/2)+1)
BaseDate11 = Month(Dateadd("M",+9,date))&"/"&Day(Dateadd("M",+9,date))&"/"&Year(Dateadd("M",+9,date))
FirstOfMonth11 = DateSerial(Year(BaseDate11), Month(BaseDate11) + iOffset, 1)
EndOfMonth11 = DateSerial(Year(BaseDate11), Month(BaseDate11) + 1, 0)
MidOfMonth11= DateSerial(Year(BaseDate11), Month(BaseDate11) + 1, -ROUND(Day(EndOfMonth11)/2)+1)
%>
<option value="<%=Month(MidOfMonth9)%>/<%=day(MidOfMonth9)%>/<%=Year(MidOfMonth9)%>"><%=Day(MidOfMonth9)%>-<%=MonthName(Month(MidOfMonth9),true)%>-<%=Year(MidOfMonth9)%></option>
<option value="<%=Month(EndOfMonth9)%>/<%=day(EndOfMonth9)%>/<%=Year(EndOfMonth9)%>"><%=Day(EndOfMonth9)%>-<%=MonthName(Month(EndOfMonth9),true)%>-<%=Year(EndOfMonth9)%></option>
<option value="<%=Month(MidOfMonth10)%>/<%=day(MidOfMonth10)%>/<%=Year(MidOfMonth10)%>"><%=Day(MidOfMonth10)%>-<%=MonthName(Month(MidOfMonth10),true)%>-<%=Year(MidOfMonth10)%></option>
<option value="<%=Month(EndOfMonth10)%>/<%=day(EndOfMonth10)%>/<%=Year(EndOfMonth10)%>"><%=Day(EndOfMonth10)%>-<%=MonthName(Month(EndOfMonth10),true)%>-<%=Year(EndOfMonth10)%></option>
i noe all this looks a bit silly and i noe not wanna continue changing the figures every now and then. any1 have an idea what i shuld do instead? i hope my question is comprehensive. thanks.
buntine
01-27-2005, 01:59 AM
Try something like this:
Dim i: i = 11
Do While i > 9
BaseDate = Month(Dateadd("M",+i,date))&"/"&Day(Dateadd("M",+i,date))&"/"&Year(Dateadd("M",+i,date))
FirstOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + iOffset, 1)
EndOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + 1, 0)
MidOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + 1, -ROUND(Day(EndOfMonth)/2)+1)
<option value="<%=Month(MidOfMonth)%>/<%=day(MidOfMonth)%>/<%=Year(MidOfMonth)%>"><%=Day(MidOfMonth)%>-<%=MonthName(Month(MidOfMonth),true)%>-<%=Year(MidOfMonth)%></option>
i = i - 1
Loop
Regards.
lmf232s
01-27-2005, 02:14 AM
buntine,
you just beat me, i was typing this up and then all of a suden,
i noticed posted a answer. Well im posting this because i
did it, and dont want the work to be wasted.
For i = 0 to 11
BaseDate = Month(Dateadd("M", + i, date)) & "/" & Day(Dateadd("M", + i, date)) & "/" & Year(Dateadd("M", + i, date))
FirstofMonth = DateSerial(Year(BaseDate), Month(BaseDate) + iOffset, 1)
EndOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + 1, 0)
MidOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + 1, -ROUND(Day(EndOfMonth)/2)+1)
MyValue = Month(MidOfMonth) & "/" & day(MidOfMonth) & "/" & Year(MidOfMonth)
MyOutPut = Day(MidOfMonth) & "-" & MonthName(Month(MidOfMonth),true) & "-" & Year(MidOfMonth)
Response.write "<option value="" & MyValue & "">" & MyOutPut & "</option><br>"
next
leeny
01-31-2005, 02:40 AM
hey guys i tried out both your codes but i gues im jus plain stupid cos i dun even noe wen to end the loop(where to put next or loop). my purpose of doing this is to display all the dates, no definite end. my codes below displays the dates all the way to 31/12/2005. any idea how i ken do an infinity thingy?or at least till 31/12/2007?please assist me. thanks in advance.
<body>
<%
BaseDate13 = Month(Dateadd("M",+11,date))&"/"&Day(Dateadd("M",+11,date))&"/"&Year(Dateadd("M",+11,date))
FirstOfMonth13 = DateSerial(Year(BaseDate13), Month(BaseDate13) + iOffset, 1)
EndOfMonth13 = DateSerial(Year(BaseDate13), Month(BaseDate13) + 1, 0)
MidOfMonth13= DateSerial(Year(BaseDate13), Month(BaseDate13) + 1, -ROUND(Day(EndOfMonth13)/2)+1)
BaseDate12 = Month(Dateadd("M",+10,date))&"/"&Day(Dateadd("M",+10,date))&"/"&Year(Dateadd("M",+10,date))
FirstOfMonth12 = DateSerial(Year(BaseDate12), Month(BaseDate12) + iOffset, 1)
EndOfMonth12 = DateSerial(Year(BaseDate12), Month(BaseDate12) + 1, 0)
MidOfMonth12= DateSerial(Year(BaseDate12), Month(BaseDate12) + 1, -ROUND(Day(EndOfMonth12)/2)+1)
BaseDate11 = Month(Dateadd("M",+9,date))&"/"&Day(Dateadd("M",+9,date))&"/"&Year(Dateadd("M",+9,date))
FirstOfMonth11 = DateSerial(Year(BaseDate11), Month(BaseDate11) + iOffset, 1)
EndOfMonth11 = DateSerial(Year(BaseDate11), Month(BaseDate11) + 1, 0)
MidOfMonth11= DateSerial(Year(BaseDate11), Month(BaseDate11) + 1, -ROUND(Day(EndOfMonth11)/2)+1)
BaseDate10 = Month(Dateadd("M",+8,date))&"/"&Day(Dateadd("M",+8,date))&"/"&Year(Dateadd("M",+8,date))
FirstOfMonth10 = DateSerial(Year(BaseDate10), Month(BaseDate10) + iOffset, 1)
EndOfMonth10 = DateSerial(Year(BaseDate10), Month(BaseDate10) + 1, 0)
MidOfMonth10= DateSerial(Year(BaseDate10), Month(BaseDate10) + 1, -ROUND(Day(EndOfMonth10)/2)+1)
BaseDate9 = Month(Dateadd("M",+7,date))&"/"&Day(Dateadd("M",+7,date))&"/"&Year(Dateadd("M",+7,date))
FirstOfMonth9 = DateSerial(Year(BaseDate9), Month(BaseDate9) + iOffset, 1)
EndOfMonth9 = DateSerial(Year(BaseDate9), Month(BaseDate9) + 1, 0)
MidOfMonth9= DateSerial(Year(BaseDate9), Month(BaseDate9) + 1, -ROUND(Day(EndOfMonth9)/2)+1)
BaseDate8 = Month(Dateadd("M",+6,date))&"/"&Day(Dateadd("M",+6,date))&"/"&Year(Dateadd("M",+6,date))
FirstOfMonth8 = DateSerial(Year(BaseDate8), Month(BaseDate8) + iOffset, 1)
EndOfMonth8 = DateSerial(Year(BaseDate8), Month(BaseDate8) + 1, 0)
MidOfMonth8= DateSerial(Year(BaseDate8), Month(BaseDate8) + 1, -ROUND(Day(EndOfMonth8)/2)+1)
BaseDate7 = Month(Dateadd("M",+5,date))&"/"&Day(Dateadd("M",+5,date))&"/"&Year(Dateadd("M",+5,date))
FirstOfMonth7 = DateSerial(Year(BaseDate7), Month(BaseDate7) + iOffset, 1)
EndOfMonth7 = DateSerial(Year(BaseDate7), Month(BaseDate7) + 1, 0)
MidOfMonth7= DateSerial(Year(BaseDate7), Month(BaseDate7) + 1, -ROUND(Day(EndOfMonth7)/2)+1)
BaseDate6 = Month(Dateadd("M",+4,date))&"/"&Day(Dateadd("M",+4,date))&"/"&Year(Dateadd("M",+4,date))
FirstOfMonth6 = DateSerial(Year(BaseDate6), Month(BaseDate6) + iOffset, 1)
EndOfMonth6 = DateSerial(Year(BaseDate6), Month(BaseDate6) + 1, 0)
MidOfMonth6= DateSerial(Year(BaseDate6), Month(BaseDate6) + 1, -ROUND(Day(EndOfMonth6)/2)+1)
BaseDate5 = Month(Dateadd("M",+3,date))&"/"&Day(Dateadd("M",+3,date))&"/"&Year(Dateadd("M",+3,date))
FirstOfMonth5 = DateSerial(Year(BaseDate5), Month(BaseDate5) + iOffset, 1)
EndOfMonth5 = DateSerial(Year(BaseDate5), Month(BaseDate5) + 1, 0)
MidOfMonth5= DateSerial(Year(BaseDate5), Month(BaseDate5) + 1, -ROUND(Day(EndOfMonth5)/2)+1)
BaseDate4 = Month(Dateadd("M",+2,date))&"/"&Day(Dateadd("M",+2,date))&"/"&Year(Dateadd("M",+2,date))
FirstOfMonth4 = DateSerial(Year(BaseDate4), Month(BaseDate4) + iOffset, 1)
EndOfMonth4 = DateSerial(Year(BaseDate4), Month(BaseDate4) + 1, 0)
MidOfMonth4= DateSerial(Year(BaseDate4), Month(BaseDate4) + 1, -ROUND(Day(EndOfMonth4)/2)+1)
BaseDate3 = Month(Dateadd("M",+1,date))&"/"&Day(Dateadd("M",+1,date))&"/"&Year(Dateadd("M",+1,date))
FirstOfMonth3 = DateSerial(Year(BaseDate3), Month(BaseDate3) + iOffset, 1)
EndOfMonth3 = DateSerial(Year(BaseDate3), Month(BaseDate3) + 1, 0)
MidOfMonth3= DateSerial(Year(BaseDate3), Month(BaseDate3) + 1, -ROUND(Day(EndOfMonth3)/2)+1)
%>
<form action="editAll.asp" method="get">
<div align="center">
<p><font color="#0000FF" size="2" face="Verdana, Arial, Helvetica, sans-serif"></font></p>
<p> <br>
<br>
</p>
<table width="54%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td colspan="2"><div align="center"><font color="#000000" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>Enter
Employee's Payroll Details </strong></font></div></td>
</tr>
<tr bgcolor="#0000CC">
<td colspan="2"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Add
Payroll </font></strong></td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="50%"><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Select
Date:</font></div></td>
<td width="50%"><select name="TxtDate" size="1" >
<option value="<%=Month(MidOfMonth2)%>/<%=day(MidOfMonth2)%>/<%=Year(MidOfMonth2)%>"><%=Day(MidOfMonth2)%>-<%=MonthName(Month(MidOfMonth2),true)%>-<%=Year(MidOfMonth2)%></option>
<option value="<%=Month(EndOfMonth2)%>/<%=day(EndOfMonth2)%>/<%=Year(EndOfMonth2)%>"><%=Day(EndOfMonth2)%>-<%=MonthName(Month(EndOfMonth2),true)%>-<%=Year(EndOfMonth2)%></option>
<option value="<%=Month(MidOfMonth1)%>/<%=day(MidOfMonth1)%>/<%=Year(MidOfMonth1)%>"><%=Day(MidOfMonth1)%>-<%=MonthName(Month(MidOfMonth1),true)%>-<%=Year(MidOfMonth1)%></option>
<option value="<%=Month(EndOfMonth1)%>/<%=day(EndOfMonth1)%>/<%=Year(EndOfMonth1)%>"><%=Day(EndOfMonth1)%>-<%=MonthName(Month(EndOfMonth1),true)%>-<%=Year(EndOfMonth1)%></option>
<option value="<%=Month(MidOfMonth)%>/<%=day(MidOfMonth)%>/<%=Year(MidOfMonth)%>"><%=Day(MidOfMonth)%>-<%=MonthName(Month(MidOfMonth),true)%>-<%=Year(MidOfMonth)%></option>
<option value="<%=Month(EndOfMonth)%>/<%=day(EndOfMonth)%>/<%=Year(EndOfMonth)%>"><%=Day(EndOfMonth)%>-<%=MonthName(Month(EndOfMonth),true)%>-<%=Year(EndOfMonth)%></option>
<option value="<%=Month(MidOfMonth3)%>/<%=day(MidOfMonth3)%>/<%=Year(MidOfMonth3)%>"><%=Day(MidOfMonth3)%>-<%=MonthName(Month(MidOfMonth3),true)%>-<%=Year(MidOfMonth3)%></option>
<option value="<%=Month(EndOfMonth3)%>/<%=day(EndOfMonth3)%>/<%=Year(EndOfMonth3)%>"><%=Day(EndOfMonth3)%>-<%=MonthName(Month(EndOfMonth3),true)%>-<%=Year(EndOfMonth3)%></option>
<option value="<%=Month(MidOfMonth4)%>/<%=day(MidOfMonth4)%>/<%=Year(MidOfMonth4)%>"><%=Day(MidOfMonth4)%>-<%=MonthName(Month(MidOfMonth4),true)%>-<%=Year(MidOfMonth4)%></option>
<option value="<%=Month(EndOfMonth4)%>/<%=day(EndOfMonth4)%>/<%=Year(EndOfMonth4)%>"><%=Day(EndOfMonth4)%>-<%=MonthName(Month(EndOfMonth4),true)%>-<%=Year(EndOfMonth4)%></option>
<option value="<%=Month(MidOfMonth5)%>/<%=day(MidOfMonth5)%>/<%=Year(MidOfMonth5)%>"><%=Day(MidOfMonth5)%>-<%=MonthName(Month(MidOfMonth5),true)%>-<%=Year(MidOfMonth5)%></option>
<option value="<%=Month(EndOfMonth5)%>/<%=day(EndOfMonth5)%>/<%=Year(EndOfMonth5)%>"><%=Day(EndOfMonth5)%>-<%=MonthName(Month(EndOfMonth5),true)%>-<%=Year(EndOfMonth5)%></option>
<option value="<%=Month(MidOfMonth6)%>/<%=day(MidOfMonth6)%>/<%=Year(MidOfMonth6)%>"><%=Day(MidOfMonth6)%>-<%=MonthName(Month(MidOfMonth6),true)%>-<%=Year(MidOfMonth6)%></option>
<option value="<%=Month(EndOfMonth6)%>/<%=day(EndOfMonth6)%>/<%=Year(EndOfMonth6)%>"><%=Day(EndOfMonth6)%>-<%=MonthName(Month(EndOfMonth6),true)%>-<%=Year(EndOfMonth6)%></option>
<option value="<%=Month(MidOfMonth7)%>/<%=day(MidOfMonth7)%>/<%=Year(MidOfMonth7)%>"><%=Day(MidOfMonth7)%>-<%=MonthName(Month(MidOfMonth7),true)%>-<%=Year(MidOfMonth7)%></option>
<option value="<%=Month(EndOfMonth7)%>/<%=day(EndOfMonth7)%>/<%=Year(EndOfMonth7)%>"><%=Day(EndOfMonth7)%>-<%=MonthName(Month(EndOfMonth7),true)%>-<%=Year(EndOfMonth7)%></option>
<option value="<%=Month(MidOfMonth8)%>/<%=day(MidOfMonth8)%>/<%=Year(MidOfMonth8)%>"><%=Day(MidOfMonth8)%>-<%=MonthName(Month(MidOfMonth8),true)%>-<%=Year(MidOfMonth8)%></option>
<option value="<%=Month(EndOfMonth8)%>/<%=day(EndOfMonth8)%>/<%=Year(EndOfMonth8)%>"><%=Day(EndOfMonth8)%>-<%=MonthName(Month(EndOfMonth8),true)%>-<%=Year(EndOfMonth8)%></option>
<option value="<%=Month(MidOfMonth9)%>/<%=day(MidOfMonth9)%>/<%=Year(MidOfMonth9)%>"><%=Day(MidOfMonth9)%>-<%=MonthName(Month(MidOfMonth9),true)%>-<%=Year(MidOfMonth9)%></option>
<option value="<%=Month(EndOfMonth9)%>/<%=day(EndOfMonth9)%>/<%=Year(EndOfMonth9)%>"><%=Day(EndOfMonth9)%>-<%=MonthName(Month(EndOfMonth9),true)%>-<%=Year(EndOfMonth9)%></option>
</select></td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" value="Continue">
</div></td>
</tr>
</table>
<p> </p>
</div>
</form>
</body>
i noe it's not right to paste one whole chunk of codes. i dunno where to end the loop if i will to use the codes you guys gave. pardon me.
buntine
01-31-2005, 05:32 AM
But the loop will end automatically. I dont understand what you mean.
leeny
01-31-2005, 07:35 PM
i placed the do while loop at the top and option value thiny in the form. however instead of being in the drop down list, i had several tables. y is it so? where should i place the codes? tht's my question
leeny
01-31-2005, 07:58 PM
i placed the do while loop at the top and option value thiny in the form. however instead of being in the drop down list, i had several tables. y is it so? where should i place the codes? tht's my question
buntine
01-31-2005, 09:31 PM
Put the loop inside the table. You dont need any of the repeating ASP code at the top of the page.
<form action="editAll.asp" method="get">
<div align="center">
<p><font color="#0000FF" size="2" face="Verdana, Arial, Helvetica, sans-serif"></font></p>
<p> <br>
<br>
</p>
<table width="54%" border="0" cellspacing="4" cellpadding="4">
<tr>
<td colspan="2"><div align="center"><font color="#000000" size="4" face="Verdana, Arial, Helvetica, sans-serif"><strong>Enter
Employee's Payroll Details </strong></font></div></td>
</tr>
<tr bgcolor="#0000CC">
<td colspan="2"><strong><font color="#FFFFFF" size="2" face="Verdana, Arial, Helvetica, sans-serif">Add
Payroll </font></strong></td>
</tr>
<tr bgcolor="#CCCCCC">
<td width="50%"><div align="right"><font size="2" face="Verdana, Arial, Helvetica, sans-serif">Select
Date:</font></div></td>
<td width="50%">
<select name="TxtDate" size="1" >
<%
Dim i: i = 11
Do While i > 9
BaseDate = Month(Dateadd("M",+i,date))&"/"&Day(Dateadd("M",+i,date))&"/"&Year(Dateadd("M",+i,date))
FirstOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + iOffset, 1)
EndOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + 1, 0)
MidOfMonth = DateSerial(Year(BaseDate), Month(BaseDate) + 1, -ROUND(Day(EndOfMonth)/2)+1)
<option value="<%=Month(MidOfMonth)%>/<%=day(MidOfMonth)%>/<%=Year(MidOfMonth)%>"><%=Day(MidOfMonth)%>-<%=MonthName(Month(MidOfMonth),true)%>-<%=Year(MidOfMonth)%></option>
i = i - 1
Loop
%>
</select>
</td>
</tr>
<tr bgcolor="#CCCCCC">
<td colspan="2"> </td>
</tr>
<tr>
<td colspan="2"><div align="center">
<input name="Submit" type="submit" value="Continue">
</div></td>
</tr>
</table>
<p> </p>
</div>
</form>
Something like that.
Regards.