我需要asp代码的帮助。我的TYPEID 3没有找到正确的链接。它默认为最后一个链接。我正在尝试从数据库中为不同的TYPEID信息设置标准链接。所有其他TYPEID的工作除了TYPE 3.任何帮助将不胜感激。
<%
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()
%>
答案 0 :(得分:0)
如果您正在检查y是偶数还是奇数,则应使用
if y mod 2 = 0 Then
使用函数使其更清晰
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
之后,清理代码以搜索问题
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