李健歌曲月光:asp 如何将商品分列显示?望高手指教!

来源:百度文库 编辑:高考问答 时间:2024/04/29 01:04:22
我的代码:
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="../Connections/conn.asp" -->
<head>
<title>products</title>
</head>
<% i=0
set rs=conn.execute("select * from products where hp='true')
while not rs.eof and i<15
%>
<body>
<table>
<tr>
<td rowspan="2"><img src="pimg/<%=rs("picture1")%>" width="100" height="150" /></td>
<% if i mod 3=0 then response.Write("</tr><tr>") end if%>
<%i=i+1
rs.movenext
wend %>
</tr>
</table>
</body>
</html>
<%rs.close%>

补充:此代码不能分列 头痛~ 希望大家能帮帮我! 谢谢!
我想要实现的效果试一页只显示15个 每行3个

table标签的位置不对,判断也要改一下,具体代码如下

<%
i=0
Set rs=conn.execute("select * from products where hp='true'")
%>
<body>
<table>
<%
while not rs.eof and i<15
if i mod 3=0 then
response.Write("<tr>")
end if
%>
<td>
<img src="pimg/<%=rs("picture1")%>" width="100" height="150" />
</td>
<%
if i mod 3=2 then
response.Write("</tr>")
end if
i=i+1
rs.movenext
wend %>
</table>
</body>
</html>
<%
rs.close
%>

sql:要打开数据的查询语句
rows:行数
cols:列数
ipage:显示第几页的数据
isShowBookMark:是否显示书签,如果你使用此函数显示于首页上,设置0--不显示
<%
sub showNews(sql,rows,cols,ipage,isShowBookMark,autoLen)
dim rs,page_size,icol,path
if cols="" or not isNumeric(cols) then cols = 1
if cols<=0 then cols = 1
if rows="" or not isNumeric(rows) then rows = 1
if rows<=0 then rows=1
if ipage="" or not isNumeric(ipage) then ipage=1
if ipage<=0 then ipage=1
if autoLen="" or not isNumeric(autoLen) then autoLen = 20
if autoLen<=0 then autoLen = 20

page_size = cols * rows
set rs = server.CreateObject("ADODB.recordset")
rs.open sql,conn,1,1
response.write "<table width=100% border=0 cellpadding=0 cellspacing=0 id=news>" & VBCRLF
if rs.eof or rs.bof then
response.write "<tr><td width=100% height=50 align=center valign=middle style='color:red'>暂时没有信息!</tr>" & VBCRLF
response.write "</table>" & VBCRLF
exit sub
end if
rs.pageSize = page_size
if int(ipage) > int(rs.pageCount) then ipage = rs.pageCount
rs.absolutePage = ipage

icol = 0
while not rs.eof and int(icol)<int(page_size)
if icol mod cols = 0 then
response.write "<tr>" & VBCRLF
end if
response.write "<td width=" & int(100/cols) & "% height=20 align=left valign=middle>" & VBCRLF
%>  ·<a href="readData.asp?id=<%=rs("id")%>&DataType=10001" target="_self"><%=autoCut(rs("title"),autoLen)%></a> <span id="time">[<%=DateValue(rs("post_time"))%>](已阅<%=rs("click_count")%>次)</span>
<%
response.write "</td>" & VBCRLF
icol = icol + 1
if icol mod cols = 0 then
response.write "</tr>" & VBCRLF
end if
rs.movenext
wend
if icol mod cols <> 0 then
response.write "<td colspan=" & int(cols - icol mod cols) & "> </td></tr>" & VBCRLF
end if
response.write "</table>"

if isShowBookMark=1 then

dim reg
set reg = new RegExp
reg.pattern = "[&]*page=[0-9]*"
reg.Global = true
reg.Ignorecase = true
path = reg.replace(request.QueryString,"")
if path="" then
path = "?" & path
else
path = "?" & path & "&"
end if
set reg = nothing

response.Write "<br><div style='font-size:12px;color:black'>" & VBCRLF
response.write "<br>总记录数<span style='color:red'>"&rs.recordCount&"</span>   每页<span style='color:red'>" & page_size & "</span>  "
if ipage <= 1 then
response.write "<span style='color:darkgray'>首页 前页</span>"
else
response.write "<a href=" & path & "page=1>首页</a> <a href=" & path & "page="&ipage-1&">前页</a>"
end if
if int(ipage) = int(rs.pageCount) then
response.write "<span style='color:darkgray'> 下页 末页</span>"
else
response.write " <a href=" & path & "page="&ipage+1&">下页</a> <a href=" & path & "page="&rs.pageCount&">末页</a>"
end if
response.write "    第"&ipage&"页 共"&rs.pageCount&"页"
response.write "</div>"

end if
end sub
%>