iT邦幫忙

0

ASP陣列群組數量問題

ChaN
初級專家
1563 466
4688 1023

假設前面表單傳來了
<input name="id" type="hidden" value="1" />
<input name="id" type="hidden" value="1" />
<input name="id" type="hidden" value="2" />
<input name="id" type="hidden" value="3" />
<input name="id" type="hidden" value="3" />
<input name="id" type="hidden" value="2" />
<input name="id" type="hidden" value="3" />
接收端這邊怎麼下可以得出
id = 1 amount: 2
id = 2 amount: 2
id = 3 amount: 3

2 個回答

12
aqr199
iT邦新手 2 級 ‧ 2010-08-22 07:25:04
最佳解答
&lt;pre class="c" name="code">
ReDim C(3)

for each item in Request("id")
	C(item) = C(item) + 1
next

for each x in C
	Response.Write "id=" & x & ",amount:" & C(x)
next
chan15 iT邦新手 5 級 ‧ 2010-08-23 12:55:13 檢舉

最後這樣搞定

&lt;pre class="c" name="code">
Dim ValName, ValSection, d
Set d = Server.CreateObject("Scripting.Dictionary")
ValName = Split(Request("visitor_name"), ",")
ValSection = Split(Request("visitor_section"), ",")

For I = 0 To Ubound(ValName)
	Section = Trim(ValSection(I))
	If d.Exists(Section) Then
		n = d.Item(Section)
		n = n + 1
		d.Item(Section) = n
	Else
		d.Add Section, 1
	End If
Next

dk = d.keys
di = d.items

For J = 0 To d.Count-1
	Response.Write(dk(J)&"共有"&di(J)&"個&lt;br />")
Next
12
外獅佬
iT邦大師 1 級 ‧ 2010-08-21 22:59:35

ASP用動態陣列??
好像不行耶
參考

我要發表回答

立即登入回答