給紙帶過濾機網(wǎng)站 添加了個提取數(shù)據(jù)庫首頁添加新聞展示代碼,提取最最后寫出的的6條新聞,怎么覺得這么丑,這么笨呢?貼出來給大家看看,像我這等大白菜也只能這樣做了,高手給個指點,更菜的可以學習。哈哈。
<%
sql = "select top 1 id,title from news order by id desc" '倒序輸出
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
title1 = rs("title")
id1 = rs("id")
sql = "select top 1 id,title from news where id<"&id1 &" order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
title2 = rs("title")
id2 = rs("id")
sql = "select top 1 id,title from news where id<"&id2 &" order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
title3 = rs("title")
id3 = rs("id")
sql = "select top 1 id,title from news where id<"&id3 &" order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
title4 = rs("title")
id4 = rs("id")
sql = "select top 1 id,title from news where id<"&id4 &" order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
title5 = rs("title")
id5 = rs("id")
sql = "select top 1 id,title from news where id<"&id5 &" order by id desc"
Set rs= Server.CreateObject("ADODB.Recordset")
rs.open sql,conn,1,1
title6 = rs("title")
id6 = rs("id")
rs.close
set rs=nothing
%>
<tr> '其實tr里邊可以加marquee動態(tài)輸出以下的文字,挺好看的。
新聞展示:
<a href="/news.asp?id=<% =id1 %> " > <% =title1 %></a>
<a href="/news.asp?id=<% =id2 %> " > <% =title2 %></a>
<a href="/news.asp?id=<% =id3 %> " > <% =title3 %></a>
<a href="/news.asp?id=<% =id4 %> " > <% =title4 %></a>
<a href="/news.asp?id=<% =id5 %> " > <% =title5 %></a>
<a href="/news.asp?id=<% =id6 %> " > <% =title6 %></a>
</tr>
'這一堆真夠長的,本來用了個數(shù)組,還有for語句,但怎么也沒搞好,哎菜呀,新手就這樣。^_^
◎歡迎參與討論,請在這里發(fā)表您的看法、交流您的觀點。
admin 于 2011-12-28 11:02:57 回復自吹自擂