1 Replies - 908 Views - Last Post: 15 July 2009 - 06:45 AM Rate Topic: -----

#1 moiseszaragoza  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 6
  • Joined: 17-February 09

SplitVar

Posted 15 July 2009 - 05:58 AM

	 	<cfset SplitVar = #URL.modelID# />
        <cfquery datasource="XXXXXXX" dbname="XXXXXX"  name="get_memb">
	
        SET QUOTED_IDENTIFIER OFF
        INSERT INTO ModelToPart
        (modelID,ModelPartID)
        VALUES
        
        <cfloop index="intI" from="1" to="#(ListLen( SplitVar, ',' )-1)#" step="1">
			<cftry>
				
               
                ('#URL.modelID#',' #ListGetAt( SplitVar, intI+1, "," )#')
                , 
				<cfcatch>
					ERROR: #CFCATCH.Message#
				</cfcatch>
			</cftry>
		</cfloop>
        
      
	</cfquery>
<cflocation url="http://www.modelproductions.com/book_NweProjct_viewPart.cfm?modelProjectID=#URL.modelProjectID#">


I am using the code above to create a Query that inserts multiple records.

Buy I have a extra coma at the end.

how can i have it that the last coma does not sohw

Thanks

Is This A Good Question/Topic? 0
  • +

Replies To: SplitVar

#2 xheartonfire43x  Icon User is offline

  • D.I.C Regular

Reputation: 46
  • View blog
  • Posts: 454
  • Joined: 22-December 08

Re: SplitVar

Posted 15 July 2009 - 06:45 AM

View Postmoiseszaragoza, on 15 Jul, 2009 - 04:58 AM, said:

I am using the code above to create a Query that inserts multiple records.

Buy I have a extra coma at the end.

how can i have it that the last coma does not sohw

Thanks


You need to do an "if" statement around it. Such as
<cfif IntI NOT EQ (ListLen( SplitVar, ',' )-2)>,</cfif>



That way it won't put a comma if it is the last item in the list.

PS rather than wrapping your code in PHP wrap it in CODE. Thats make it a lot easier to read here.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1