hi peeps,

i have here a code of the contents in a field fetched from the database. the ProductID is looped until all are displayed, which depends on the sql. i put a comma after a ProductID so that all ProductIDs are displayed separated by a comma and a single space. my problem is that after the last ProductID, there is still a comma displayed. how can i remove the comma after the last ProductID??

hope you got what i mean and can help me with this problem.

thank you once again and more power to you & daniweb!!

<%do until rsprd.eof%>
<%'sTotal = 1%>
<%lght = Len(rsprd("ProductID"))%>
<%if lght = 1 then%>
	<%if rsprd.recordcount = 1 then%>
		<font size="2" face="Arial" color="#000000">P-000<%=rsprd("ProductID")%>,</font>
	<%else%>
		<font size="2" face="Arial" color="#000000">P-000<%=rsprd("ProductID")%>,</font>
	<%end if%>
<% elseif lght =2 then%>
	<%if rsprd.recordcount = 1 then%>
		<font size="2" face="Arial" color="#000000">P-00<%=rsprd("ProductID")%>,</font>
	<%else%>
		<font size="2" face="Arial" color="#000000">P-00<%=rsprd("ProductID")%>,</font>
	<%end if%>
<%elseif lght = 3 then%>
	<%if rsprd.recordcount = 1 then%>
		<font size="2" face="Arial" color="#000000">P-0<%=rsprd("ProductID")%>,</font>
	<%else%>
		<font size="2" face="Arial" color="#000000">P-0<%=rsprd("ProductID")%>,</font>
	<%end if%>
<%elseif lght = 4 then%>
	<%if rsprd.recordcount = 1 then%>
		<font size="2" face="Arial" color="#000000">P-<%=rsprd("ProductID")%>,</font>
	<%else%>
		<font size="2" face="Arial" color="#000000">P-<%=rsprd("ProductID")%>,</font>
	<%end if%>
<%end if%>

<%rsprd.Movenext
loop
sTotal = sTotal + (rsprd.recordcount)%>				
				
<%'else%>
&nbsp;
<%'end if%>
</font>
<%end if%>

You would be better off building the output into a variable rather than writing it directlt to the sreen as part of the loop. You can then use the LEFT and STRLEN functions to trim the required number of characters from the end of the resultant variable. An example:

tempStr = ""
x=1
do while x<=10
tempStr = tempStr & x & ","
loop
'// output would be
'// 1,2,3,4,5,6,7,8,9,10,
tempStr = left(tempStr, strlen(tempStr)-1)
'// output would be
'// 1,2,3,4,5,6,7,8,9,10
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.