| | |
How can i remove the comma?
Please support our ASP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
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!!
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!!
ASP Syntax (Toggle Plain Text)
<%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%> <%'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:
ASP Syntax (Toggle Plain Text)
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
If I've been a help please confirm by clicking the Add to Lafinboy's Reputation link in the header of this reply.
Lafinboy Productions
:: Website Design :: Website Development ::
Lafinboy Productions
:: Website Design :: Website Development ::
![]() |
Similar Threads
- Runtime Error 5 - Need help please (Visual Basic 4 / 5 / 6)
- Remove IE from desktop? (Web Browsers)
- Dynamic Array, Writing to CSV, Floating Point ?'s (C)
- Cant add/remove win components (Windows NT / 2000 / XP)
- Jscript Replace Function (ASP)
- cant remove program from ad and remove programs (Windows NT / 2000 / XP)
Other Threads in the ASP Forum
- Previous Thread: Problem with input
- Next Thread: Save and Add Another
Views: 2638 | Replies: 1
| Thread Tools | Search this Thread |
Tag cloud for ASP
archive asp asp.net aspandmssqlserver2005 aspandmssqlserver2005connection aspconnection calendar changeable connection current database databaseconnection diagnostics dreamweaver excel fso html iis microsoft msmsql mssql2005 mssqlserver2005 mssqlserver2005andasp mssqlserverandasp opentextfile query record searchbox selectoption server single specfic sqlserver sqlserverconnection toolkit update web webserver windows7





