相似三角形简单例题:¤¤ ASP中列出多条不同类型的数据记录的问题 ¤¤

来源:百度文库 编辑:神马品牌网 时间:2024/04/30 02:11:23
在论坛的数据库中有一用户发帖表,这个表里存放论坛中各个版面的用户发帖,现在想在网站首页列出论坛中十条最新的帖子,这十条帖子分别都是论坛中十个版块中的最新一条,每个帖子的记录中都有一个名为“type”的字段名标示,用于表示他属于哪一个版块的。
也就是:
当type=1,表示论坛中的第一个版块。
当type=2,表示论坛中的第二个版块。
…………
type=10,第十个版块。

要实现在首页中列出这来自不同版块的十条记录,除了建立十个记录集(ADODB.RecordSet),分别用:
rs1.open "select * from table where type=1 order ……"
rs2.open "select * from table where type=2 order ……"
……
rs10.open "select * from table where type=10 order ……"
然后再分别显示出来rs1到rs10之外。

还有其它什么方法吗? 比这简单、便捷的。
都有几种方法? 谢谢。

方法好的,再加分。

if exists (select * from dbo.sysobjects where id = object_id(N'[dbo].[table]') and OBJECTPROPERTY(id, N'IsUserTable') = 1)
drop table [dbo].[table]
GO

CREATE TABLE [dbo].[table] (
[fid] [int] IDENTITY (1, 1) NOT NULL ,
[title] [varchar] (50) COLLATE Chinese_PRC_CI_AS NOT NULL ,
[type] [int] NOT NULL
) ON [PRIMARY]
GO

测试表

一个 fid 自增长编号
一个 title 主题描述
一个 type 类型编号

如果你的帖子id是自增长编号的话那就很好
不过一般 都是自增长编号 所以直接使用以下语句就可以了

select fid, type, title
from [table]
where fid in
(
select top 10 max(fid) from [table] group by type order by type
)
order by type

返回的结果集可以自己选

用数组
<%
dim Navigation()
dim type(10)
sql="select * from table order ……"
set rs=conn.execute(sql)
if rs.bof and rs.eof then
Rows=-1
response.Write(" ")
else
Assay=Rs.GetRows
Rows=Ubound(Assay,2)
end if
rs.close
for i = 0 to Rows
if Assay(type在数据中的列数,i) = i+1 and type(i+1) <> 1 then
'所想要显示的内容
type(i+1) = 1
end if
next
%>
自己去试一下吧,不行的话就用二重循环检查。
我的QQ:416672046