关于动态生成表格的代码问题

yunbao 2008-04-13 09:54:12
以下代码代码Category是新闻类别表,News是新闻的内容,下面的代码实现一行只能有1个类别的新闻显示,显示特别不好看,我想让一行有2个类别的新闻显示怎么办呢 还有"更多信息..."我想让它显示在类别的右边空几格的地方
这可能是我的html语言不熟悉吧
有请高手教教我 不胜感激啊!!!

<div id="Layer35">
<%
sql="SELECT * FROM Category ORDER BY CateId"
Set rsCate = conn.Execute(sql)
%>
<%
If rsCate.BOF = False Then
rsCate.MoveFirst
End If
Do while not rsCate.EOF
stitle = rsCate("CateName")
cid = rsCate("CateId")
cnt = 0
Response.Write "<table width='100%' cellspacing=1 cellpadding=2><tr>"
Response.Write stitle + " ==</td></tr>"
Response.Write "<table width='100%' border=0 cellspacing=0 ceppadding=0>"
sql = "SELECT * FROM News WHERE CateId=" & cid & "order by Posttime desc"
rs.Open sql,conn,1,1
Do while not rs.eof
cnt = cnt + 1
if cnt < 11 Then
Dim ndate
ndate = DateAdd("d",-3,date())
Response.Write "<tr><td width='50%'><a onclick='return newwin(this.href);' href='NewsView.asp?id=" + cstr(rs("id")) + "'> "+ rs("Title")+ ""
if rs("Attpic") Then
Response.Write "(附图)"
Response.Write "</a>"
End If
If datediff("d",rs("Posttime"),ndate+time()) <= 0 Then
Response.Write "<img src='pic/new.gif' ALT='最新的信息!' border=0></td>"
End IF
End If
rs.MoveNext
Loop
Response.Write "</table>"
Response.Write "<p align='right'><a href='#top'>top</a>"
Response.Write "  "
Response.Write "<a target='_self' href='Category.asp?flag="+ CStr(cid) +"'>更多信息...</a></p>"
Response.Write "</td></tr></table></td></table>"
rs.Close
rsCate.MoveNext
loop
%>
</div>
...全文
112 点赞 收藏 16
写回复
16 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
yunbao 2008-04-17
看来今天又要无眠了
回复
yunbao 2008-04-17
我比如


界面是这样的:


国内新闻:
23123213
213213213
2134123 ...更多信息
国外新闻:
32453455
546546546
675676577 ...更多信息
日常新闻:
32453455
546546546
675676577 ...更多信息



这样太不好看了

我想改成:

国内新闻: ...更多信息 国外新闻: ...更多信息
23123213 32453455
213213213 546546546
2134123 675676577

日常新闻:
32453455
546546546
675676577 ...更多信息

不只两个类别啊 有十几个来 上面的那只是2个类别用的
我还没有想到 请教各位 谢谢了
回复
yunbao 2008-04-13
<div id="Layer35">
<%
sql = "select * from Category order by CateId"
Set rsCate = conn.Execute(sql)
cnn = 0
If rsCate.BOF = False Then
rsCate.MoveFirst
End If
Do while not rsCate.EOF
cnn = cnn + 1
sttitle = rsCate("CateName")
cid = rsCate("CateId")
cnt = 0
Response.Write "<table width='100%' border='0' cellspacing=0 cellpadding=2><tr>"
If cnn = 1 or (cnn mod 2) <> 0 then
Response.Write "<th width='46%' align='left' scope='col'>"+sttitle+"</th>"
Else
Response.Write "<th width='54%' align='left' scope='col'>"+sttitle+"</th>"
Response.Write "</tr>"
End if
rsCate.MoveNext
Loop
Response.Write "</table>"
%>
</div>


我改的有问题呀 高手快来帮助我啊
回复
yunbao 2008-04-13
在线等。。。
回复
yunbao 2008-04-13
自己顶一个
回复
lishishui1216 2008-04-13
<table>
<tr>
<td>
<table>
<tr>
<td>
国内新闻
</td>
</tr>
<%
循环显示国内新闻
%>
<tr>
<td>
</td>
</tr>
<%
循环结束
%>
</table>
</td>
<td>
<table>
<tr>
<td>
国外新闻
</td>
</tr>
<%
循环显示国外新闻
%>
<tr>
<td>
</td>
</tr>
<%
循环结束
%>
</table>
</td>
</tr>
<table>
这样应该也可以实现你要的效果哦!
回复
Dogfish 2008-04-13
使用浮动的div。
<table>
<tr>
<td>
<div style="float:left">
国内新闻:
23123213
213213213
2134123 ...更多信息
</div>
<div style="float:left">
国外新闻:
32453455
546546546
675676577 ...更多信息
</div>
</td>
</tr>
</table>
回复
yunbao 2008-04-13
我比如


界面是这样的:


国内新闻:
23123213
213213213
2134123 ...更多信息
国外新闻:
32453455
546546546
675676577 ...更多信息


这样太不好看了

我想改成:

国内新闻: ...更多信息 国外新闻: ...更多信息
23123213 32453455
213213213 546546546
2134123 675676577

大家帮帮我
回复
yunbao 2008-04-13
界面乱了啊
回复
-晴天 2008-04-13

<div id="Layer35">
<%
Dim ndate
sql="SELECT * FROM Category ORDER BY CateId"
Set rsCate = conn.Execute(sql)
If rsCate.BOF = False Then
rsCate.MoveFirst
End If
Do while not rsCate.EOF
cid = rsCate("CateId")
cnt = 0
Response.Write " <table width='100%' cellspacing=1 cellpadding=2> <tr><td>"
Response.Write rsCate("CateName") + " == </td></tr>"
Response.Write "<tr><td><table width='100%' border=0 cellspacing=0 ceppadding=0>"
sql = "SELECT * FROM News WHERE CateId=" & cid & "order by Posttime desc"
rs.Open sql,conn,1,1
Do while not rs.eof
cnt = cnt + 2
if cnt < 11 Then
response.write "<tr>"
for j=1 to 2
Response.Write "<td width='50%'>
if not rs.eof then
ndate = DateAdd("d",-3,date())
Response.Write "<td width='50%'> <a onclick='return newwin(this.href);' href='NewsView.asp?id=" + cstr(rs("id")) + "'> "+ rs("Title")+ ""
if rs("Attpic") Then
Response.Write "(附图)"
End If
Response.Write "</a>"
If datediff("d",rs("Posttime"),ndate+time()) <= 0 Then
Response.Write " <img src='pic/new.gif' ALT='最新的信息!' border=0> "
End IF
end if
response write "</td>"
next
response.write "</tr>"
End If
rs.MoveNext
Loop
Response.Write " </table>"
Response.Write " <p align='right'> <a href='#top'>top </a>"
Response.Write "  "
Response.Write " <a target='_self' href='Category.asp?flag="+ CStr(cid) +"'>更多信息... </a>      </p>"
Response.Write " </td> </tr> </table> </td> </table>"
rs.Close
rsCate.MoveNext
loop
%>
</div>
回复
sql="SELECT * FROM Category where CateName='国内新闻' or CateName='国外新闻' ORDER BY CateId"
这样写SQL就只是显示国内新闻与国外新闻了
回复
你到底想干嘛?难道我写得不符合你的?
回复
yunbao 2008-04-13
这下好像一行把所有的类别都显示了
还是很难解决呀
我想了好久了。。。 谢谢大家再帮帮我吧
回复
mataofq 2008-04-13
全部Response.Write?????
还是考虑下性能,在client里定制一个样式然后用server填充吧
回复
myvicy 2008-04-13
讲一个方法:自己先写一个静态的html,然后再把这个静态的用动态内容替换一下就可以了。大多数都可以这样来处理。
回复
<% 
sql="SELECT * FROM Category ORDER BY CateId"
Set rsCate = conn.Execute(sql)
%>
<%
If rsCate.BOF = False Then
rsCate.MoveFirst
End If
Response.Write " <table width='100%' cellspacing=1 cellpadding=2> <tr>"
Do while not rsCate.EOF
stitle = rsCate("CateName")
cid = rsCate("CateId")
cnt = 0
Response.Write " <td>"

Response.Write " <table width='100%' border=0 cellspacing=0 ceppadding=0>"
Response.Write "<tr><td>"
Response.Write stitle + " == </td></tr>"
sql = "SELECT * FROM News WHERE CateId=" & cid & "order by Posttime desc"
rs.Open sql,conn,1,1
Do while not rs.eof
cnt = cnt + 1
if cnt < 11 Then
Dim ndate
ndate = DateAdd("d",-3,date())
Response.Write " <tr> <td width='50%'> <a onclick='return newwin(this.href);' href='NewsView.asp?id=" + cstr(rs("id")) + "'> "+ rs("Title")+ ""
if rs("Attpic") Then
Response.Write "(附图)"
Response.Write " </a>"
End If
If datediff("d",rs("Posttime"),ndate+time()) <= 0 Then
Response.Write " <img src='pic/new.gif' ALT='最新的信息!' border=0>"
End IF
response.Write " </td></tr>"
End If
rs.MoveNext
Loop
Response.Write " </table></td><td align='right'>"
Response.Write "<a href='#top'>top </a>"
Response.Write "  "
Response.Write " <a target='_self' href='Category.asp?flag="+ CStr(cid) +"'>更多信息... </a> </td>"

rs.Close
rsCate.MoveNext
loop
Response.Write "</tr></table>"
%>
</div>



直接拿去用就行了
回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
申请成为版主
帖子事件
创建了帖子
2008-04-13 09:54
社区公告
暂无公告