要想顯示美觀可以自己設定樣式
<%
dim maxCount '希望顯示的資訊數
maxCount=10
dim lineCount '希望一行顯示的資訊數
lineCount=4
'判斷資料庫中現有資訊的條數
sql="select * from News where BigClassName='公司動態'"
set rs=server.CreateObject("ADODB.recordset")
rs.open sql,conn,1,1
dim rc
rc=rs.Recordcount
response.Write("<table width='1000' height='500' border='0'>")
'判斷資料庫中的資料是否比maxCount少,少了就顯示在一行中
if rc <= lineCount then
response.Write("<tr>")
do while not rs.eof
response.Write("<td>"&rs("Title")&"</td>")
rs.movenext
loop
response.Write("</tr>")
rs.close
set rs=nothing
'資料庫中的資料大於maxCount
else
dim fuzhu
fuzhu=0
rs.close
set rs=nothing
sql1="select top "& maxCount &" * from News where BigClassName='公司動態'"
set rs1=server.CreateObject("ADODB.recordset")
rs1.open sql1,conn,1,1
response.Write("<tr>")
do while not rs1.eof
if fuzhu mod lineCount=0 then
response.Write("</tr><tr>")
end if
response.Write("<td>"&rs1("Title")&"</td>")
fuzhu=fuzhu+1
rs1.movenext
loop
rs1.close
set rs1=nothing
response.Write("</tr>")
end if
response.Write("</table>")
%>