如何把数据库里的4000条记录的文章内容批量生成静态页html

来源:互联网 发布:淘宝开直通车有效果吗 编辑:程序博客网 时间:2024/05/22 06:44
发表于:2007-07-04 16:26:49 楼主
请教高手。如何把数据库里的4000条记录的文章内容批量生成静态页html?用循环么?   用哪个循环?for   each   next   ?   谁能发一个完整的代码?谢谢

备注:我考虑用一个模板页temp.html(替换方法),从data数据库读取记录,生成4000个以时间顺序为文件名的页面(2007070412319.html)。生成方法我会的,就是不知道如何循环生成一个个页面。生成的页面:包含标题、内容、日期,就是像新闻网站一样的静态页。

请提示!!
发表于:2007-07-05 15:15:412楼 得分:0
答案已经出来了。昨夜调试到1点睡的,喝了点咖啡,失眠了,3点才睡着。5点有人敲门,告诉我做饭的家什被盗啦,一个又脏又旧的破煤气罐被拎走了。我晕,什么事啊!!!害的的出去吃饭。北京小偷够疯狂,3天内一个院偷走2个煤气罐,一辆自行车,还有几家的空调主机,,都穷疯了,惊动了110。哎,不说了,我把代码贴出来,供大家以后参考吧。

Do   While   dr.Read()
                        Dim   title   =   dr.Item( "title ")
                        Dim   clsss   =   dr.Item( "class ")
                        Dim   t   =   dr.Item( "t ")
                        Dim   laiyuan   =   dr.Item( "laiyuan ")
                        Dim   content   =   dr.Item( "content ")
                        Dim   smallclass   =   dr.Item( "smallclass ")
                        Dim   file_name   =   dr.Item( "file_name ")
                        '下面首先读取模板文件,将其中的全部代码保存到一个字符串中
                        Dim   strTemplate   As   String
                        Dim   sr   As   New   IO.StreamReader(Server.MapPath( "template.htm "),   Encoding.GetEncoding( "gb2312 "))
                        strTemplate   =   sr.ReadToEnd()
                        sr.Close()
                        '下面利用客户输入的内容替换模板中的相应字符串
                        strTemplate   =   strTemplate.Replace( "$title$ ",   title)
                        strTemplate   =   strTemplate.Replace( "$class$ ",   clsss)
                        strTemplate   =   strTemplate.Replace( "$t$ ",   t)
                        strTemplate   =   strTemplate.Replace( "$laiyuan$ ",   laiyuan)
                        strTemplate   =   strTemplate.Replace( "$content$ ",   content)
                        strTemplate   =   strTemplate.Replace( "$smallclass$ ",   smallclass)
                        strTemplate   =   strTemplate.Replace( "$file_name$ ",   file_name)
                        '下面建立一个StreamWriter对象,生成HTML文件
                        Dim   sw   As   New   IO.StreamWriter(Server.MapPath(file_name),   False,   Encoding.GetEncoding( "gb2312 "))
                        sw.Write(strTemplate)
                        sw.Close()
                Loop

我准备这周结帖子,大家只要回复就有分。散分啦!
原创粉丝点击