ASP问题

aarongame 2008-04-09 12:02:18
<% dim conn
set conn = server.createobject("adodb.connection")
conn.open = "provider=microsoft.jet.oledb.4.0;" & "data source = " & server.mappath("../../newstest.mdb")
set rs = conn.execute("select top 4 * from news where bigclass='行业动态'")
do while not rs.eof
response.write " <div> <a href=news_detail.asp?id="&rs("news_id")&">" & rs("news_subject") & " </a> </div>"

rs.movenext
loop
set rs = nothing
conn.close
set conn = nothing
%>

我用ASP做出来的新闻页,具体新闻内容页面news_detail.asp该怎么做?为什么我做出来的不能和新闻列表一一对应?用绑定的纪录集拉出来做的,不行,那该怎么做
...全文
105 点赞 收藏 20
写回复
20 条回复
切换为时间正序
当前发帖距今超过3年,不再开放新的回复
发表回复
hookee 2008-04-09
news_detail.asp
<%
news_id = Request.QueryString("news_id")
If Not isNumeric(news_id) Then
Response.Write "无效字符"
Response.End
End If

dim conn
set conn = server.createobject("adodb.connection")
conn.open = "provider=microsoft.jet.oledb.4.0;" & "data source = " & server.mappath("../../newstest.mdb")
set rs = createobject("adodb.recordset")
rs.cursorLocation = 3
rs.open "select * from news where id=" & news_id
If not (rs.eof and rs.bof) Then
response.write Replace(rs("content"),VBCrLf,"<br>")
End If
If rs.state<>0 Then rs.close
set rs = nothing
conn.close
set conn = nothing
%>
回复
Atai-Lu 2008-04-09
总之,只要能在数据库里找到对应的记录即可
回复
Atai-Lu 2008-04-09
dim id
id = Request("id")
if not isnumeric(id) or id="" then id=0
...
sql="select * from news where [id]="&id
...
回复
myvicy 2008-04-09
怎么不对应了?是不是detail里写的不对?
回复
heshengfen123 2008-04-09
晕死了,把这个直接复制进去试试
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 
<!--#include file="Connections/mynews.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows
dim id
id=request("id")
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_mynews_STRING
Recordset1.Source = "SELECT * FROM news where news_id="&id
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<%=(Recordset1.Fields.Item("bigclass").Value)%>
</form>
<form id="form2" name="form2" method="post" action="">
<p align="center"> <%=(Recordset1.Fields.Item("news_subject").Value)%> </p>
<p align="right"> <%=(Recordset1.Fields.Item("news_faburen").Value)%> </p>
</form>
<form id="form3" name="form3" method="post" action="">
   
<%=(Recordset1.Fields.Item("news_content").Value)%>
</form>
<form id="form4" name="form4" method="post" action="">
<div align="right"> <%=(Recordset1.Fields.Item("news_adddate").Value)%>
</div>
</form>
<p>  </p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>
回复
itzhiren 2008-04-09
晕,你根本都没改

按照9楼的提示改一改吧
回复
aarongame 2008-04-09
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/mynews.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_mynews_STRING
Recordset1.Source = "SELECT * FROM news"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<%=(Recordset1.Fields.Item("bigclass").Value)%>
</form>
<form id="form2" name="form2" method="post" action="">
<p align="center"> <%=(Recordset1.Fields.Item("news_subject").Value)%> </p>
<p align="right"> <%=(Recordset1.Fields.Item("news_faburen").Value)%> </p>
</form>
<form id="form3" name="form3" method="post" action="">
   
<%=(Recordset1.Fields.Item("news_content").Value)%>
</form>
<form id="form4" name="form4" method="post" action="">
<div align="right"> <%=(Recordset1.Fields.Item("news_adddate").Value)%>
</div>
</form>
<p>  </p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

从绑定的纪录集中拉出来纪录做成的
回复
itzhiren 2008-04-09
再把news_detail.asp这个页面的代码拿来看看
回复
aarongame 2008-04-09
Recordset1.Source = "SELECT * FROM news where news_id="&id
改成这个还是出错..还是:
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] 语法错误 (操作符丢失) 在查询表达式 'id=' 中。
/newstest/news_detail.asp, 第 14 行
回复
heshengfen123 2008-04-09
如果news_id唯一的话可以照上面那样修改,
不唯一则要加上循环
回复
heshengfen123 2008-04-09
Recordset1.Source = "SELECT * FROM news where news_id="&id

不好意思,改成这个
回复
aarongame 2008-04-09
Recordset1.Source = "SELECT * FROM news where id="&id
这一句好像有问题吧?
回复
bing110 2008-04-09
呵呵,你用的代码应该是别人那里复制过来吧,其实不用那么复杂的。那些Form要看你表的记录以你要达到的目的,如果没有用的话,可以删除的。
回复
aarongame 2008-04-09
form是表单,控制位置的...
你的出错了,
Microsoft OLE DB Provider for ODBC Drivers (0x80040E14)
[Microsoft][ODBC Microsoft Access Driver] 语法错误 (操作符丢失) 在查询表达式 'id=' 中。
/newstest/news_detail.asp, 第 14 行

怎么改
回复
heshengfen123 2008-04-09
还有出现那么多个form是为了什么
回复
heshengfen123 2008-04-09
你的代码中传递过来的ID都没用的,试一下这个
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%> 
<!--#include file="Connections/mynews.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows
dim id
id=request("id")
Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_mynews_STRING
Recordset1.Source = "SELECT * FROM news where id="&id
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档 </title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<%=(Recordset1.Fields.Item("bigclass").Value)%>
</form>
<form id="form2" name="form2" method="post" action="">
<p align="center"> <%=(Recordset1.Fields.Item("news_subject").Value)%> </p>
<p align="right"> <%=(Recordset1.Fields.Item("news_faburen").Value)%> </p>
</form>
<form id="form3" name="form3" method="post" action="">
   
<%=(Recordset1.Fields.Item("news_content").Value)%>
</form>
<form id="form4" name="form4" method="post" action="">
<div align="right"> <%=(Recordset1.Fields.Item("news_adddate").Value)%>
</div>
</form>
<p>  </p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

回复
aarongame 2008-04-09
<%@LANGUAGE="VBSCRIPT" CODEPAGE="936"%>
<!--#include file="Connections/mynews.asp" -->
<%
Dim Recordset1
Dim Recordset1_numRows

Set Recordset1 = Server.CreateObject("ADODB.Recordset")
Recordset1.ActiveConnection = MM_mynews_STRING
Recordset1.Source = "SELECT * FROM news"
Recordset1.CursorType = 0
Recordset1.CursorLocation = 2
Recordset1.LockType = 1
Recordset1.Open()

Recordset1_numRows = 0
%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head>
<body>
<form id="form1" name="form1" method="post" action="">
<%=(Recordset1.Fields.Item("bigclass").Value)%>
</form>
<form id="form2" name="form2" method="post" action="">
<p align="center"><%=(Recordset1.Fields.Item("news_subject").Value)%></p>
<p align="right"><%=(Recordset1.Fields.Item("news_faburen").Value)%></p>
</form>
<form id="form3" name="form3" method="post" action="">
   
<%=(Recordset1.Fields.Item("news_content").Value)%>
</form>
<form id="form4" name="form4" method="post" action="">
<div align="right"><%=(Recordset1.Fields.Item("news_adddate").Value)%>
</div>
</form>
<p> </p>
</body>
</html>
<%
Recordset1.Close()
Set Recordset1 = Nothing
%>

从绑定的纪录集中拉出来纪录做成的
回复
heshengfen123 2008-04-09
把news_detail.asp这个页面的代码拿来看看
回复
aarongame 2008-04-09
数据库中都有纪录,但是现在问题是不管点哪个新闻标题出来的链接的新闻内容都是一样的,最新的那条
回复
heshengfen123 2008-04-09
conn.open = "provider=microsoft.jet.oledb.4.0;" & "data source = " & server.mappath("../../newstest.mdb")

不用这个
conn.open "provider=microsoft.jet.oledb.4.0;" & "data source = " & server.mappath("../../newstest.mdb")

回复
相关推荐
发帖
ASP
创建于2007-09-28

2.8w+

社区成员

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