I need assistance with asp code. My TYPEID 3 is not going to the correct link. It is defaulting to the last link. I'm trying to set the standard link for different TYPEID 's information from a database. All the other TYPEID's work with the exception of TYPE 3. Any help would be appreciated.
<%
set objRS = Server.CreateObject("ADODB.Recordset")
strSql = "SELECT * from product_types order by product_types.sortorder;"
objRS.Open strSql, objConn, adOpenDynamic, adLockOptimistic
If objRS.EOF then
response.write "There is currently an error with the store.</p>"
Else
y=0
While not objRS.EOF
' set objRSrandomimg = Server.CreateObject("ADODB.Recordset")
' strSQLrandomimg = "SELECT products.*, product_pubtype.* FROM products INNER JOIN product_pubtype ON products.pubtype = product_pubtype.PUBTYPEID WHERE (product_pubtype.pubtypeimage = 1) AND (products.instock = 1) AND (products.type = " & objRS("TYPEID") & ")"
' objRSrandomimg.Open strSQLrandomimg, objConn, adOpenStatic, adLockReadOnly
' rndMax = CInt(objRSrandomimg.RecordCount)
' objRSrandomimg.MoveFirst
' Randomize Timer
' rndNumber = Int(RND * rndMax)
' objRSrandomimg.Move rndNumber
y=y+1
If y mod 2 = 1 Then
If objRS("TYPEID")=5 then
%>
< tr>
< td valign="bottom">
< a href="/store/listitems2.asp?type=5&prodcat=22">
<%=objRS("typename")%>
< /a>
</td>
<%
else
%>
< tr>
< td valign="bottom">
< a href="/store/listitems.asp?type=<%=objRS(" TYPEID ")%>">
<%=objRS("typename")%>
< /a>
</td>
<%
End If
Else
If objRS("TYPEID")=4 then
%>
< tr>
< td valign="bottom">
< a href="/store/listitems2.asp?type=<%=objRS(" TYPEID ")%>&prodcat=21">
<%=objRS("typename")%>
< /a>
</td>
<%
elseif objRS("TYPEID")=3 then
%>
< tr>
< td valign="bottom">
< a href="/store/listitems2.asp?type=<%=objRS(" TYPEID ")%>&prodcat=17">
<%=objRS("typename")%>
< /a>
</td>
<%
elseIf objRS("TYPEID")=2 then
%>
< tr>
< td valign="bottom">
< a href="/store/listitems2.asp?type=<%=objRS(" TYPEID ")%>&prodcat=16">
<%=objRS("typename")%>
< /a>
</td>
<%
else
%>
< td valign="bottom">
< a href="/store/listitems.asp?type=<%=objRS(" TYPEID ")%>">
<%=objRS("typename")%>
< /a>
</td>
< /tr>
<%
End If
End If
' objRSrandomimg.Close
' Set objRSrandomimg = Nothing
objRS.movenext
Wend
If y mod 2 = 1 Then
%>
< td> & nbsp;
< /td>
</tr>
<%
End If
%>
< tr>
< td colspan="2">
< a href="/store/listitems.asp"> Show All
< /a>
</td>
< /tr>
< /table>
<%
End If
' response.write randomstoreid()
%>
If your are checking if y is even or odd, you should use
if y mod 2 = 0 Then
Use a function to put it more clear
If IsEven(y) Then
...
End if
Function IsEven(ByVal numberToCheck)
If numberToCheck Mod 2 = 0 Then
IsEven = True
Else
IsEven = False
End if
End Function
After that, clean your code to search for problems
While not objRS.EOF
y=y+1
If IsEven(y) Then
response.Write "Even and type=" + objRS("TYPEID") + "<br>"
If objRS("TYPEID")=5 then
else
End If
Else
response.Write "Odd and type=" + objRS("TYPEID") + "<br>"
If objRS("TYPEID")=4 then
elseif objRS("TYPEID")=3 then
response.Write "Success!<br>"
elseIf objRS("TYPEID")=2 then
else
End If
End If
objRS.movenext
Wend
Related
I have an html form that has to update contact data. But... each contact has a number of cars with related information viewed as table rows with input cells within the same form. Cars information has to be updated too. The number of cars for each person is not known in advance. How can I handle this in the Server with Request.Form;
Thanks
<form action="#" method="post">
<table>
<tr><td>ID</td><td>INFO1</td><td>INFO2</td><td>INFO3</td></tr>
<%While Not rsVechicles.Eof%>
<tr>
<td><input name="VechicleID" value=<%=rsVechicles("VechicleID")%> /></td>
<td><input name="info1" value=<%=rsVechicles("info1")%> /></td>
<td><input name="info2" value=<%=rsVechicles("info2")%> /></td>
<td><input name="info3" value=<%=rsVechicles("info3")%> /></td>
</tr>
<%rsVechicles.MoveNext%>
<%Wend%>
</table>
You need to have some sort of counter variable to differentiate between the rows. Also, do you really mean for the user to be able to change the vehicle ID?
<%
dim v
v = 0
%>
<form method="post" action="thispage.asp">
<table><tr><th>ID</th><th>Info 1</th><th>Info 2</th><th>Info 3</th></tr>
<%
While Not rsVehicles.EOF
v = v + 1
Response.Write "<tr><td><input type='hidden' name='ID_" & v & "'"
Response.Write " value='" & rsVehicles("VehicleID") & "'>"
Response.Write rsVehicles("VehicleID") & "</td>"
For i = 1 to 3
Response.Write "<td><input type='text' name='Info" & i & "_" & v & "'"
Response.Write " value='" & rsVehicles("Info" & i) & "'></td>"
Next
Response.Write "</tr>"
rsVehicles.Movenext
Wend
Response.Write "<input type='hidden' name='N' value='" & v & "'>"
%>
</table>
Then when you're reading values from the form, you can loop through the same indexes:
v = Request.Form("N") '- number of vehicles
For i = 1 to v
Vehicles(i,0) = Request.Form("ID_" & i)
For j = 1 to 3
Vehicles(i,j) = Request.Form("Info" & j & "_" & i)
Next
Next
Like the date with would print in column 1 to 30, I need need employee login time and log off time in single days column ...``
I need to print data in table like single row with multiple columns in classic asp
<form name="frm_display" method="post">
Welcome: <%=Session("emp_fname")%>
<br>ID: <%=Session("emp_id")%>
<%
dim con
dim query
dim rs2
set con = Server.CreateObject("ADODB.Connection")
set rs2 = Server.CreateObject( "ADODB.RECORDSET")
con.Open "Provider=SQLOLEDB.1;Password=swtest.net;Persist Security Info=True;User ID=sa;Initial Catalog=hr;Data Source=172.16.1.208"
%>
<table align="center">
<tr>
<td>Month:
<select name="selmonth">
<%for i=1 to 12%>
<%if cint(SelectedMonth)=i then%>
<option selected value="<%=i%>">
<%=monthname(i)%>
</option>
<%else%>
<option value=< %=i%>>
<%=monthname(i)%>
</option>
<%end if%>
<%next%>
</select>
Year:
<select name="selyear">
<%for i=2000 to year(now)%>
<option select value=<%=i%>>
<%=i%>
</option>
<%next%>
</select>
<input type="Submit" value="Submit" name="btn_submit">
</td>
</tr> <!-- <-- missing! -->
</table>
</form>
<%
dim dt
dt = "1-" & monthname(Request.Form("sel_month")) & "-" & Request.Form("sel_year")
query = "select e.emp_id,e.emp_name,e.CompDepart,e.des_name,U.login_time,U.logoff_time,U.login_date " &_
"from egv_emp_departments e " &_
"inner join login_mast U on U.emp_id=e.emp_id " &_
"where month(login_date)='" & request.form("selmonth") &_
"' AND year(login_date)='" & request.form("selyear") &_
"' AND e.emp_id='" & Session( "emp_id") & "'"
rs2.open query,con
%>
<table border="1" width="100%">
<tr> <!-- added missing tr tag -->
<td>emp_id</td>
<td>emp_name</td>
<td>CompDepart</td>
<td>des_name</td>
<%
dim intDay
dim daysInMonth
dim strMonth
dim stryear
intDay=1
strMonth = request("selmonth")
stryear = request("selyear")
If strMonth <> "" Then
If stryear <> "" Then
Select Case strMonth
Case 1,3,5,7,8, 10,12 daysInMonth = 31
Case 4, 6, 9, 11 daysInMonth = 30
Case 2
if stryear mod 4 = 0 Then
If stryear mod 100 = 0 AND stryear mod 400 <> 0 Then
daysInMonth = 28
Else
daysInMonth = 29
End if
Else
daysInMonth=28
End if
End Select
Do While intDay <= daysInMonth
Response.Write "<td>" & intDay & "</td>"
intDay = intDay + 1
Loop
Else
End if
End if
for each x in rs2.fields ' <-- fixed typo "feilds"
response.write "<th>" & x.name & "<th>"
next
%>
</tr> <!-- added missing /tr tag -->
<%do until rs2.EOF %>
<tr>
<%for each x in rs2.Fields%>
<td>
<%Response.Write(x.value)%>
</td>
<% next %>
<% rs2.MoveNext %>
</tr>
<%loop
rs2.close
con.close %>
</table>
At first, I thought you wanted what's called a "PivotTable" in Excel, but then I noticed that you're filtering to a single employee. It's still not clear to me what you mean by "single days column" vs. "like single row with multiple column", but I assume you mean something like:
Employee: Smith, John
ID: 123456
Month: March
—————————————————
Day | In | Out
1 | 8 | 5
2 | 8 | 5
3 | - | -
4 | 9 | 5
... | ... | ...
30 | 9 | 4
31 | 8 | 4
—————————————————
In other words, your problem is that there might be days with no data, but you still want to print those rows. The simplest way to handle that is probably a temp table with the numbers 1 through 31 in it, which you then use in an outer join with the rest of your query. If you can't do that (e.g. you're not allowed to create temp tables - don't laugh, it happens), then you can do it in code instead.
The easiest way to do it in code is to put the values from the database into an array, but not by using GetRows. Instead, put each day's value into the corresponding row of the array.
dim listdays(31,1)
...
Do Until rs2.EOF
dt = Day(rs2("login_date"))
listdays(dt,0) = rs2("login_time")
listdays(dt,1) = rs2("logoff_time")
rs2.Movenext
Loop
(I'll pause while the purists finish having conniptions. Trust me, any performance hit from using Movenext on a recordset that contains, at most, 31 rows, is going to be so infinitesimal as to be nonexistent.)
Then you simply write out the contents of the array.
Response.Write "<table><tr><th>Day</th><th>Login</th><th>Logoff</th></tr>"
For i = 1 to DaysInMonth
Response.Write "<tr>"
Response.Write "<th>" & i & "</th>"
Response.Write "<td>" & listdays(i,0) & "</td>"
Response.Write "<td>" & listdays(i,1) & "</td>"
Response.Write "</tr>"
Next
Response.Write "</table>"
I was wondering if someone could help me out.
I need to work out a range that a dynamic number sits in.
For example, i have a script like so
<% upperlimit = 50000.0 %>
<% lowerlimit = -30000.0 %>
<%=Int((upperlimit - lowerlimit + 1)*Rnd() + lowerlimit) %>
This spits out the value 30366.
The upperlimit and lowerlimit are dynamic so i dont know what the output would be.
This value is in the range 30001 - 40000 ... How can i get those values dynamically?
Cheers
I believe this example covers your situation:
<%
max=100
min=1
Randomize
%>
<%=Int((max-min+1)*Rnd+min)%>
Update 1
<% upperlimit = 50000.0 %>
<% lowerlimit = -30000.0 %>
<% range = 10000 %>
<% newValue =Int((upperlimit - lowerlimit + 1)*Rnd() + lowerlimit) %>
<% lowerBand=(newValue\range)*range %>
<% upperBand=lowerBand+range %>
<%=newValue%>
<br>
<%=lowerBand+1%>-<%=upperBand%>
if you wanted to generate 30000-40000
<%
Dim MyNewRandomNum
Randomize
MyNewRandomNum = Int(Rnd * 10000)+30000
response.write MyNewRandomNum
%>
the value you random
30000 is minimal value
and 10000 is value you wanted to random (1-10000)
i hope this is you want
This works for both negative and positive values of newValue:
<%
dim upperlimit, lowerlimit, newValue, lowerBand, upperBand
upperlimit = 50000.0
lowerlimit = -30000.0
Randomize
newValue = Int((upperlimit - lowerlimit + 1)*Rnd + lowerlimit)
lowerBand = Fix(newValue/10000) * 10000 + Sgn(newValue)
upperBand = Sgn(lowerBand) * 10000 + lowerBand - Sgn(newValue)
response.write "newValue: " & newValue & "<br>"
response.write "lowerBand: " & lowerBand & "<br>"
response.write "upperBand: " & upperBand & "<br>"
%>
Please see Running example
I have a table (MSSQL) with data like:
1 AAA 100
2 BBB 101
3 C 100
4 D 100
I would like to list itens like:
100:
- 1 AAA
- 3 C
- 4 D
101:
- 2 BBB
How can I do this? I have done a While inside a While but the result isn't what I am waiting:
<%
Set Group= TarefasConexaoMSSQL.Execute("SELECT DISTINCT GroupName FROM _NewDummy")
GroupName= Group("GroupName")
WHILE NOT Group.EOF
%>
<p>
<% Response.Write Group("GroupName") %>
</p>
<%
Set Itens= TarefasConexaoMSSQL.Execute("SELECT * FROM _NewDummy WHERE GroupName= '"& GroupName &"'")
One= Itens("One")
Two= Itens("Two")
%>
<%
WHILE NOT Itens.EOF
%>
- One: <% Response.Write One %>
- Two: <% Response.Write Two %>
<%
Itens.MOVENEXT
WEND
%>
<%
Group.MOVENEXT
WEND
%>
Thanks for any info on this.
You don't need any nested loop here, just sort by the group name and keep track of the previous value vs. the current value. When the value changes (or first value) show the group name.
Code:
<%
Set oRS= TarefasConexaoMSSQL.Execute("SELECT * FROM _NewDummy ORDER BY GroupName ASC")
Dim currentGroupName, previousGroupName
currentGroupName = ""
previousGroupName = ""
Do Until oRS.EOF
currentGroupName = oRS("GroupName")
One = oRS("One")
Two = oRS("Two")
If currentGroupName<>previousGroupName Then
Response.Write("<p>")
Response.Write("" & currentGroupName & "")
Response.Write("</p>")
End If
Response.Write("- One: " & One & ", Two: " & Two & "<br />")
previousGroupName = currentGroupName
oRS.MoveNext
Loop
oRS.Close
%>
I have done an Active Server Page. It is running on a foyerdisplay. The ASP is displaying meetings on that Display. I limited the displaying meetings to 10. The display can display 5-6 meeting at a time. What i want is that if the display is filled with the first 6 meetings the display should "change" to a second page which displays the last 4 meeting. That should happen every 10 seconds. 10 Seconds the first 6 meetings, 10 seconds the 4 meetings and so on. How can I do that?
My Code so far:
<table cellpadding="0" style="table-layout:fixed;width:800px;">
<tr height="15"> <td colspan="6" class="underline"></td> </tr>
<colgroup>
<col style="width:830px" >
</colgroup>
<tr><td> </td></tr>
</table>
<table cellpadding="0" border = "1" style="background-color:white; dotted black;border-collapse:collapse;table-layout:fixed;width:1270px;">
<colgroup>
<col style="width:445px" >
<col style="width:275px" >
<col style="width:125px" >
<col style="width:125px" >
<col style="width:150px" >
<col style="width:150px" >
</colgroup>
<br></br>
<tr style="background-color:blue; height="50">
<th align="left">Seminartitel</th>
<th align="left">Zusatz-Info</th>
<th align="absmiddle">von</th>
<th align="absmiddle">bis</th>
<th align="absmiddle">Gebäude</th>
<th align="absmiddle">Raum</th>
</tr>
<%
set rs=Server.CreateObject("ADODB.recordset")
set rsRaum=Server.CreateObject("ADODB.recordset")
rs.Open "select distinct buchung_id, von, bis, abteilung, veranstalter, THEMA, THEMA_ENABLED " & _
" from RESERVIERUNGRAUM r " & _
" ,BUCHUNG b " & _
" where r.BUCHUNG_ID = b.ID " & _
" and von >= convert(date, getdate(), 4) " & _
" and von < convert(date, dateadd(day,1, GETDATE()), 4) " & _
" and BIS >= getdate() " & _
" and STORNO is null " & _
" order by von, bis" _
,objConn
' Anzahl der darzustellenden Veranstaltungs-Zeilen
lineMax = 10
lineCount = 1
color = "color1"
do until rs.EOF
' Buchungen anzeigen oder nicht
rsRaum.open "select DISPLAY_ENABLED from Buchung where ID = " & rs("buchung_id"), objConn
displayanzeige = rsRaum("DISPLAY_ENABLED")
rsRaum.close
' Hole für lfd. Buchung aus erster Reservierung Raum ID und Indikator für Kopplung
rsRaum.open "select raum_id, KOPPELBESTUHLUNG_ID from RESERVIERUNGRAUM where buchung_id = " & rs("buchung_id"), objConn
raum_id = rsRaum("raum_id")
KOPPELBESTUHLUNG_ID = rsRaum("KOPPELBESTUHLUNG_ID")
rsRaum.close
'Gebäude
rsRaum.open "select distinct g.BEZEICHNUNG " & _
"from GEBAEUDE g, ETAGE e, RAUM r " & _
"Where g.ID = e.GEBAEUDE_ID and e.GEBAEUDE_ID = r.GEBAEUDE_ID and r.ID = " & raum_id, objConn
GebaeudeBezeichnung = rsRaum("BEZEICHNUNG")
rsRaum.close
'Hole Terminal Hinweistext
rsRaum.open "select KSTR from Buchung where ID = " & rs("buchung_id"), objConn
Hinweistext = rsRaum("KSTR")
rsRaum.close
' falls Kopplung, hole ID des "Parent"-Raumes
if not isNull( KOPPELBESTUHLUNG_ID ) then
rsRaum.open "select parent_id from KOPPELN where CHILD_ID = " & raum_id, objConn
if not rsRaum.EOF then
raum_id = rsRaum("parent_id")
end if
rsRaum.close
end if
' hole Raum Details
rsRaum.open "select bezeichnung from Raum where ID = " & raum_id, objConn
raumname = rsRaum("bezeichnung")
rsRaum.close
' Beende, falls Display voll
If lineCount > lineMax Then
exit do
End If
' optionale Unterdrückung der Titelanzeige
if ucase( rs("thema_enabled") ) = "Y" or isnull(rs("thema_enabled")) then
thema = rs("thema")
else
thema = ""
end if
if ucase(displayanzeige) = "Y" or isnull(displayanzeige) then
%>
<tr "margin-bottom:100px" height="70" valign="top">
<td style="overflow:hidden;" class="<% =color%>"><% =thema %></td>
<td class="<% =color%>"><% =Hinweistext %></td>
<td align="center"; class="<% =color%>"><% =FormatDateTime( rs("von"), 4)%></td>
<td align="center"; class="<% =color%>"><% =FormatDateTime( rs("bis"), 4) %></td>
<td align="center"; class="<% =color%>"><% =GebaeudeBezeichnung %><br></td>
<td align="center"; class="<% =color%>"><% =raumname %><br></td>
</tr>
<%
' jede zweite Zeile mit anderer Schriftfarbe
If lineCount mod 2 = 1 Then
color = "color2"
Else
color = "color1"
End If
lineCount = lineCount + 1
end if
rs.moveNext
loop
rs.close
%>
How can I modify my Code?
Create a duplicate page and pass a parameter (GET or POST) to it as RemainingItems from current page. RemainingItems here is 4 and change the current page as following:
If lineCount > lineMax Then
TO be:
If lineCount > firstPageItems Then
obviously:
lineMax = firstPageItems + RemainingItems
For switching between pages, in specific intervals, you should use JavaScript timer on both pages. After time elapsed, redirect the client to the other page (each page knows the address of the other).
It is possible to do all the work in one page but since it need more work, according to question I suggest this one.