从数据库中循环读出符合条件的某个字段记录 并加到一个字符串 记录之间用逗号分开

haonanernet 2005-04-23 10:03:22
<form name="form1" method="post" action="sendsms_s.asp"align="right">

<table width="80%" align="right"height="167" border="0">
<tr>
<td> </td>
<td><font color="#FF0000">查找结果:</font></td>
</tr>
<tr>
<td width="13%">  </td>
<td width="87%"> 共找到符合上述条件的用户
<%
idayfrom=request("idayfrom")
idayto=request("idayto")
sex=request("sex")
edu=request("edu")
bdayfrom=request("bdayfrom")
bdayto=request("bdayto")
Set rs = Server.CreateObject("ADODB.Recordset")
sql="select * from person where sex='"&sex&"'and edu='"&edu&"'and bday between '"&bdayfrom&"'and '"&bdayto&"' and mobiletype=1"
rs.open sql,conn,1,1
redim a(cint(rs.recordcount))
i=0
do while not rs.eof
a(i+1)=a (i)&","&rs("shouji")
i=i+1
rs.movenext
Loop
%>
<%=rs.recordcount%> 位<input type="text" name="mobilecode" value="<%=a(cint(rs.recordcount))%>"></td>
</tr>
<tr>
<td> </td>
<td><font color="#FF0000">向以上用户发送短信:</font> </td>
</tr>
<tr>
<td height="70" align="right">内容: </td>
<td><textarea name="textarea"></textarea>
(请不要超过70个汉字) </td>
</tr>
<tr>
<td> </td>
<td><input type="submit" name="Submit" value="发送短信"> </td>
</tr>
</table>
</form>



但是这句话 a(i+1)=a (i)&","&rs("shouji")
查出来的值为 " ,,13812312312"
而不是 ",13812312312,13812345678"不知道为什么


其实我就通过循环把数据库中符合条件的手机号显示到一个字符串或者一个字符数组里面
并且之间用 逗号 连接 如: ,13812312312,13812345678,......
不知道大家有没有其他好的方法
...全文
224 8 打赏 收藏 转发到动态 举报
写回复
用AI写文章
8 条回复
切换为时间正序
请发表友善的回复…
发表回复
haonanernet 2005-04-24
  • 打赏
  • 举报
回复
查出来是str=,13812312312,13812345678,......
怎么样去掉最前面的逗号
超级大笨狼 2005-04-24
  • 打赏
  • 举报
回复
ID 父亲ID 名字
1 0 祖宗
2 1 山本1
3 1 山本2
4 1 山本3
5 1 山本4
6 1 山本5
7 2 山本11
8 2 山本12
9 2 山本13
10 2 山本14
11 3 山本21
12 3 山本22
13 3 山本23
14 3 山本24
15 6 山本51
16 6 山本52
17 6 山本53
18 6 山本54
19 6 山本55
20 6 山本56
21 4 山本31
22 4 山本32
CREATE TABLE [dbo].[tree] (
[ID] [int] IDENTITY (1, 1) NOT NULL ,
[父亲ID] [int] NULL ,
[名字] [varchar] (50) COLLATE Chinese_PRC_CI_AS NULL
) ON [PRIMARY]

要求查询结果

1,用逗号分开的儿子的名单字符串。
2,用逗号分开的全部后代名单字符串。
3,辈份数。
4,在同父兄弟中的排行数 。
5,排序按照http://www.adr.gov.cn/download/panyuguang/DDM/left/menu.asp
的形式从上到下


--生成儿子名单的函数
CREATE function f_childID(@id int)
returns varchar(8000)
as
begin
declare @re table(id int,level int)
declare @l int,@r varchar(8000)
set @l=0
insert into @re select id,@l
from tree where 父亲ID=@id
while @@rowcount>0
begin
set @l=@l+1
insert into @re select a.id,@l
from tree a inner join @re b on a.父亲ID=b.id
where b.level=@l-1
end
set @r=''
select @r=@r+','+ltrim(str(id) ) from @re
return(substring(@r,2,8000))
end

1 0 祖宗 2,3,4,5,6,7,8
2 1 山本1 7,8
3 1 山本2
4 1 山本3
5 1 山本4
6 1 山本5
7 2 山本11
8 2 山本12


  • 打赏
  • 举报
回复
thepos=instr(str,",")
str=mid(str,thepos+1)
haonanernet 2005-04-24
  • 打赏
  • 举报
回复
没有用过,我只想去掉最前面的那个 "," 请大哥出手
  • 打赏
  • 举报
回复
instr 那个,
用mid的方法去掉,,不懂的话我写一个出来
haonanernet 2005-04-24
  • 打赏
  • 举报
回复
查出来是str=,13812312312,13812345678,......
怎么样去掉最前面的逗号
谢谢
jonath 2005-04-23
  • 打赏
  • 举报
回复
你这样用数组,a(i+1)=a (i)&","&rs("shouji"),那么a(0)=?,你知道吗?
用str=str & "," & rs("shouji")
要得到数组的话,等循环执行完,用a=split(str,",")就可以了,a就是你想要的数组
scoutlin 2005-04-23
  • 打赏
  • 举报
回复
redim preserve a(cint(rs.recordcount))

28,406

社区成员

发帖
与我相关
我的任务
社区描述
ASP即Active Server Pages,是Microsoft公司开发的服务器端脚本环境。
社区管理员
  • ASP
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧