在网上介绍如何编写制作论坛的文章不少,但据我观察大多数的代码都有不同程度的错误,会误导大家。所以我写这篇文章的目的就是把经过我测试成功的代码与思路提供给大家。下面就让我们从数据库的建立开始:
用access建立数据库:
首先我们要建立一个存放帖子的数据库,在这里我介绍用access2000建立数据库的方法。
我们先要建立一个名为news.mdb的数据库文件,然后在其中点“新建”选择“设计视图”建立两个表,一个名为details用来存放回复,另一个名为titles用来存放主题如图:
制作过程详解:
在titles中建立以下字段,如图:
注意:
| 1 | 右键单击“titleID”选择“主键”,出现钥匙图形。 |
| 2 | 这里的“shu”不可以改为“number”否则会出现错误,王国容的那本《asp & web 数据库》中就犯了这样的错误。 |
| 3 | 将“日期/时间”类型的字段的默认值都设为now() |
在titles中建立以下字段,如图:
将“日期/时间”类型的字段的默认值都设为now()。建立完成后,要设置这两个表的关联。点击 按钮,出现如下对话框:
将titles中的titleID拖至details中的titleID上松手,出现如下对话框:(如图设置)
然后保存就可以了。这样一个提供储存的数据库就建立好了。接下来我们要编写asp程序了。首先让我们先来分析论坛所需要的功能。大概需要以下几个功能:
| 1 | 显示主题 |
| 2 | 发布主题 |
| 3 | 显示回复 |
| 4 | 发布回复 |
于是,我们根据这些功能,需要编写6个asp文件:
title.asp、titlenew.asp、titleout.asp、detail.asp、detnew.asp、detout.asp
还有一个文件是必需的(在我的程序中)adovbs.inc,它提供程序中的常数值如:“adopenstatic”。(点击这里下ADOVBS.INC载源文件)每个文件的代码:
title.asp:
| <%@LANGUAGE="VBSCRIPT" CODEPAGE="CP_ACP"%> <!--#include virtual="adovbs.inc"--> <!--#include file="titleout.asp"--> <% const head="我的论坛" dbpath=server.MapPath("news.mdb") set conn=server.CreateObject("adodb.connection") conn.open"driver={Microsoft Access Driver (*.mdb)};dbq="&dbpath sql="select titleID,createdate as 主题发布时间,lastnewsdate as 最后回复时间,name as 作者,shu as 回复篇数,subject as 主题 from titles order by lastnewsdate desc" set rs=server.CreateObject("adodb.recordset") rs.open sql,conn,adopenstatic %> <html> <head> <title><%=head%></title> <meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <style type="text/css"> <!-- body { font-family: "宋体"; font-size: 12px} table { font-family: "宋体"; font-size: 12px} a:link { font-family: "宋体"; font-size: 12px; color: #000000; text-decoration: none} a:visited { font-family: "宋体"; font-size: 12px; color: #666666; text-decoration: none} a:hover { font-family: "宋体"; font-size: 12px; color: #ff3300; text-decoration: underline} --> </style> </head> <body> <!--输出主题--> <% rs.pagesize=10 page=clng(request("page")) if page<1 then page=1 if page>rs.pagecount then page=rs.pagecount %> <form action="title.asp" method="get"> <table border="0" cellpadding="0" cellspacing="0" width="90%"> <tr> <td align="right" width="100%"> <% if page<>1 then response.Write("<a href=title.asp?page=1>第一页</a> ") response.Write("<a href=title.asp?page="&(page-1)&">上一页</a> ") end if if page<>rs.pagecount then response.Write("<a href=title.asp?page="&(page 1)&">下一页</a> ") response.Write("<a href=title.asp?page="&rs.pagecount&">最后一页</a> ") end if %> 转到第<input type="text" name="page" size="3">页 页码:<font color="#FF0000"><%=page%></font>/<font color="#FF0000"><%=rs.pagecount%></font> </td> </tr> </table> </form> <center> <table border="0" bgcolor="#999999" cellpadding="3" cellspacing="1" width="780"> <tr bgcolor="#00FFFF"> <td height="18" width="150" align="center">主题发布时间</td> <td height="18" width="350" align="center">主题</td> <td height="18" width="100" align="center">作者</td> <td height="18" width="30" align="center">回复</td> <td height="18" width="150" align="center">最后回复时间</td> </tr> <% On Error Resume Next rs.absolutepage=page for i=1 to rs.pagesize titleoutput rs rs.movenext if rs.eof then exit for next %> </table> </center> <form action="title.asp" method="get"> <table border="0" cellpadding="0" cellspacing="0" width="90%"> <tr> <td align="right" width="100%"> <% if page<>1 then response.Write("<a href=title.asp?page=1>第一页</a> ") response.Write("<a href=title.asp?page="&(page-1)&">上一页</a> ") end if if page<>rs.pagecount then response.Write("<a href=title.asp?page="&(page 1)&">下一页</a> ") response.Write("<a href=title.asp?page="&rs.pagecount&">最后一页</a> ") end if %> 转到第<input type="text" name="page" size="3">页 页码:<font color="#FF0000"><%=page%></font>/<font color="#FF0000"><%=rs.pagecount%></font> </td> </tr> </table> </form> <!--下面为输入表单--> <form action="titlenew.asp" method="post"> <center> <table border="0"> <tr> <td>姓名:</td> <td><input type="hidden" size="30" name="name" value="<%=session("name")%>"><%=session("name")%></td> </tr> <tr> <td>信箱:</td> <td><input type="text" size="30" name="Email" value="<%=session("Email")%>"></td> </tr> <tr> <td>主题:</td> <td><input type="text" size="60" name="subject"></td> </tr> <tr> <td>内容:</td> <td><textarea name="words" rows="8" cols="60"></textarea></td> </tr> <tr> <td align="center" colspan="2"><input type="submit" value="提交"> <input type="reset" value="清空"></td> </tr> </table> </center> </form> </body> </html>
文章整理:西部数码--专业提供域名注册、虚拟主机服务 0
相关文章
最新评论共有 0 位网友发表了评论
查看所有评论
发表评论
热点关注
相关文章
IDC资讯
虚拟主机
域名注册
托管租用
vps主机
智能建站
网站运营 建站经验 策划盈利 搜索优化 网站推广 免费资源 网站联盟 联盟新闻 联盟介绍 联盟点评 网赚技巧 行业资讯 业界动态 搜索引擎 网络游戏 门户动态 电子商务 广告传媒 网络编程 Asp.Net编程 Asp编程 Php编程 Xml编程 Access Mssql Mysql 服务器技术 Web服务器 Ftp服务器 Mail服务器 Dns服务器 安全防护 软件技巧 Word Excel Powerpoint Ghost Vista QQ空间 QQ FlashGet 迅雷 Internet Explorer 网页制作 FrontPages Dreamweaver Javascript css photoshop fireworks Flash 程序设计 Java技术 C/C++ VB delphi 网络知识 网络协议 网络安全 网络管理 组网方案 Cisco技术 操作系统 Win2000 WinXP Win2003 Mac OS Linux FreeBSD |



