从数据库中循环读出符合条件的某个字段记录 并加到一个字符串 记录之间用逗号分开
<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,......
不知道大家有没有其他好的方法
问题点数:100、回复次数:8Top
1 楼scoutlin(挖摸追挖摸追挖摸追..)回复于 2005-04-23 22:07:43 得分 20
redim preserve a(cint(rs.recordcount))Top
2 楼jonath(汪汪)回复于 2005-04-23 22:52:29 得分 20
你这样用数组,a(i+1)=a (i)&","&rs("shouji"),那么a(0)=?,你知道吗?
用str=str & "," & rs("shouji")
要得到数组的话,等循环执行完,用a=split(str,",")就可以了,a就是你想要的数组Top
3 楼haonanernet(与时俱进)回复于 2005-04-24 00:15:49 得分 0
查出来是str=,13812312312,13812345678,......
怎么样去掉最前面的逗号
Top
4 楼haonanernet(与时俱进)回复于 2005-04-24 08:04:41 得分 0
查出来是str=,13812312312,13812345678,......
怎么样去掉最前面的逗号
谢谢Top
5 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2005-04-24 08:17:13 得分 60
instr 那个,
用mid的方法去掉,,不懂的话我写一个出来Top
6 楼haonanernet(与时俱进)回复于 2005-04-24 08:40:32 得分 0
没有用过,我只想去掉最前面的那个 "," 请大哥出手Top
7 楼liuxiaoyi666(MSMVP 小猪妹荣誉马甲之八卦兔子)回复于 2005-04-24 08:55:50 得分 0
thepos=instr(str,",")
str=mid(str,thepos+1)Top
8 楼superdullwolf(超级大笨狼,每天要自强,MVP)回复于 2005-04-24 09:08:45 得分 0
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
Top




