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该怎么做?为什么我做出来的不能和新闻列表一一对应?用绑定的纪录集拉出来做的,不行,那该怎么做
...全文
136 20 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
20 条回复
切换为时间正序
请发表友善的回复…
发表回复
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")

28,409

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧