asp文章上一篇,下一篇实现代码
来源:asp之家 发布时间:2008-03-24 20:15:00
标签:sql,上一篇,下一篇,查询
新闻、文章系统中经常会用到的一个功能,添加上一篇,下一篇或相关文章的功能可以增加访客停留的时间。也许新人在做这上一篇、下一篇功能时使用的是ID+1或ID-1 的sql查询语句,这样做的缺点时当文章自动编号不连续时,就查询不到数据了。正确的方法应该是使用ID>pid或ID<pid,其中pid是当前文章的id。
下面的函数就是使用这个方法:
Rem==上一篇==
Rem================================================================
Rem= 参数说明:
Rem= pid当前ID,prame:栏目前辍(如一般web_news表,字段时一般为wn_**,prame就代表wn)
Rem= ptable(表前辍.如一般表名是:站点名_表名(shenzhe_news) ptable:就代表shenzhe)
Rem= 说明:采用上面命名法,可使该过程达到通用
Rem===============================================================
Function GetPre(pid,prame,ptable)
id = prame&"_id"
title = prame&"_title"
table = "city_"&ptable
url = "show_"&ptable
sql = "SELECT TOP 1 "&id&","&title&" FROM "&table&" WHERE "&id&"<"&pid&" ORDER BY "&id&" DESC"
set rs = Conn.Execute(sql)
If rs.eof or rs.bof Then
pre = "上一篇:没有新闻了"
Else
pre = "<a href="&url&".asp?"&id&"="&rs(0)&">"&rs(1)&"</a>"
End If
GetPre = pre
End Function
Rem = 下一篇
Rem=============
Rem= 参数函意和上过程一样
Rem==========
Function GetNext(nid,nrame,ntable)
id = nrame&"_id"
title = nrame&"_title"
table = "city_"&ntable
url = "show_"&ntable
sql = "SELECT TOP 1 "&id&","&title&" FROM "&table&" WHERE "&id&">"&nid&" ORDER BY "&id&" "
set rs = Conn.Execute(sql)
If rs.eof or rs.bof Then
nnext = "下一篇:没有新闻了"
Else
nnext = "<a href="&url&".asp?"&id&"="&rs(0)&">下一篇:"&rs(1)&"</a>"
End If
GetNext = nnext
End Function
实现代码:
偶数据库里有表:
city_active city_date city_note
city_active主要字段有: ca_id,cd_title
city_date主要字段有: cd_id,cd_title
city_note主要字段有: cn_id, cn_title
这样引用就可:
在show_new.asp?cn_id=4里引用上一篇下一篇
<%=GetPre(cn_id,"cn","note")%> ' 上一篇
<%=GetNext(cn_id,"cn","note")%> ' 下一篇
0
投稿
猜你喜欢
- 在python中启动和关闭线程:首先导入threadingimport threading然后定义一个方法def serial_read()
- 首先给大家分享一个个人在使用python的ctypes调用c库的时候遇到的一个小坑这次出问题的地方是一个C函数,返回值是malloc生成的字
- 编这个程序是想过节过年,一些重要的纪念日,给亲戚好友发祝福之类的,但要凌晨0点才显得比较有诚意,可我又比较贪睡,常常忘了,所以就有了编个微信
- PHP有效的时间戳典型范围是格林威治时间 1901 年 12 月 13 日 20:45:54 到 203
- format()函数"""测试 format()函数"""def t
- 实现效果先看看效果这比我手动的快多了,而且是单机的,自动玩没惹骂我,哈哈 ,多人游戏整个自动玩会被骂死~代码没装软件的先安装一下软件,没装模
- 以下代码实现环境是mac系统,本地配置mysql服务端和navicat premium客户端,python环境是配置了pymysql的ana
- 前言网上很多例子都说cv2.minAreaRect函数的输出的角度范围在[-90,0],但是实测输出范围在[0,90]。再进行调研,确定为o
- 说明1、字典运算中的键必须是不可变类型,如整数(int)、浮点数(float)、字符串(str)、元组(tuple)等。2、列表(list)
- 关于选课程序,最近着实有点忙,没机会复习os、pickle两部分模块,所以数据储存和字典读取成为了一个问题,大致原理知道,但是具体操作可能还
- 思路:创建浏览器驱动对象加载登录页面等待页面加载完毕切换到用户名和密码登录模式输入手机号, 注意此处需要等待并获取输入框输入密码点击验证按钮
- 一、读取整个文件内容在读取文件之前,我们先创建一个文本文件resource.txt作为源文件。resource.txtmy name is
- 前言python的类分别有新式类和经典类,都支持多继承。在类的继承中,如果你想要重写父类的方法而不是覆盖的父类方法,这个时候我们可以使用su
- etcd组件作为一个高可用强一致性的服务发现存储仓库.etcd作为一个受到ZooKeeper与doozer启发而催生的项目,除了拥有与之类似
- 1. 什么是XSLT 大家可能听说过XSL(eXtensible Stylesheet Language),XSL和我们这里说的XSLT从狭
- 本文实例讲述了php多进程中的阻塞与非阻塞操作。分享给大家供大家参考,具体如下:我们通过pcntl_fork来创建子进程,使用pcntl_w
- 高斯模糊的介绍与原理通常,图像处理软件会提供"模糊"(blur)滤镜,使图片产生模糊的效果。"模糊"
- python中实现静态方法和类方法都是依赖于python的修饰器来实现的。 对象方法有self参数,类方法有cls参数,静态方法是不需要这些
- 前言from collections import namedtuple()命名元祖的工厂函数:在python中,collections 包
- 简单用py写了一个贪吃蛇游戏,有单人、双人模式,比较简单,适合初学者练手。本上每行重要的语句都有注释,做了什么事一目了然这里介绍双人模式单人