上一篇文章我们写了如何用ASP简单连接MySql数据库,这次我们直接贴代码,asp调用织梦dedecms的文章列表。
<%
set conn=Server.Createobject("adodb.Connection")
str="dsn=conn;Driver={mysql driver};server=127.0.0.1;uid=root;pwd=root;database=help"
conn.open(str)
'response.Write(conn.state) '显示连接状态,若为1表示连接成功,若为0连接失败。
sql = "select * from dede_archives where typeid='6' order by pubdate desc limit 2,5"
set rs = conn.execute(sql)
if not rs.bof then
do while not rs.eof
sql = "select * from dede_arctype where id='6'"
set rss = conn.execute(sql)
worldLen=28
%>
<li><a target="_blank" href="https://你的网址<%=rss("typedir")&"/"&rs("id")%>.html" title="<%=rs("title")%>"><i>【<%=formatdatetime(FromUnixTime(rs("pubdate"), +8),2)%>】</i> <span><%=FixString(Replace(rs("title"),"""","\"""), worldLen, 2)%></span></a></li>
<%
rss.close
rs.movenext
loop
rs.close
end if%>
代码具体的意思是从ID为6的栏目中读取id,typedir,title,按日期输出第2-5条内容。
你学会了吗?