账号通
    

账号  

密码  

7466

查看

10

回复
主题:[技巧]自定义sql标签实现自动取循环次数 [收藏主题] 本贴被认定为精华 转到:  
科汛官方 当前离线

47268

主题

145

广播

405

粉丝
添加关注
级别:管理员

用户积分:101604 分
登录次数:7935 次
注册时间:2006/12/7
最后登录:2023/12/14
科汛官方 发表于:2008/7/16 9:06:00   | 显示全部帖子 查看该作者主题 楼主 
科汛在线商城系统(NET)

在解答商业用户时,发现有用户需要,就和大家一起分享:


如我们在用下拉列表做,推荐文章时,可能下拉选项是不固定的,举例如下


<select name='url' onchange="location.href=this.value;">


 <option value="http://xxxx">文章标题...</option>


 ...


</select>


 


sql语句:


select id,tid,title from ks_article order by id desc


sql循环体如下:


<select name='url' onchange="location.href=this.value;">


  [loop=n]


<option value="{$Field(ID,GetInfoUrl,1,1)}">[{$Field(Tid,GetClassUrl,1,0)}]{$Field(Title,Text,0,...,0,)}</option>


[/loop]
</select>


 


 


 


由于现在的sql标签必须明确的指定循环次数,这时就有点不好办了,如果n指定一个太大的数字可能会导致资源的浪费


 


不难办,只需稍改下程序代码,即可实现自动获得记录数的目的.


 


请打开KS_Cls/Kesion.SqlCls.asp,并找到,约200多行


 


'替换循环部分内容
  Function GetCirLabelContent(CirLabelContent,ByRef KS_RS_Obj,LoopTimes)
  Dim regEx, Matches, Match, TempStr
  Dim FieldParam,FieldParamArr,FieldName,FieldType,ReturnFieldValue
  Dim DB_FieldValue,FieldParamLength,I,FieldPosition,N
   If Not IsNumeric(LoopTimes) Then LoopTimes=10
   If LoopTimes=0 Then LoopTimes=KS_RS_Obj.RecordCount


 


 


加上红色的那句即可.


 


那接下来,我们的循环体就可以这样写


 


<select name='url' onchange="location.href=this.value;">


  [loop=0]


<option value="{$Field(ID,GetInfoUrl,1,1)}">[{$Field(Tid,GetClassUrl,1,0)}]{$Field(Title,Text,0,...,0,)}</option>


[/loop]
</select>


 


即将n设为0

 
  支持(0) | 反对(0) 回到顶部顶端 回到底部底部
<上一主题 | 下一主题 >
Powered By KesionCMS Version X1
厦门科汛软件有限公司 © 2006-2016 页面执行0.04688秒 powered by KesionCMS 9.0