| Posted By |
Discussion Topic: Letter Sequence
|
|
jaco5md |
08-23-2005 @ 1:59 PM |
|
|
Senior Member
Posts: 492
Joined: Jul 2005
|
I am creating a page that takes data from Page 1 and then creates child data for that data. Example: Data 1 ---- Data 1a ---- Data 1b I cannot figure out how to automatically sequence letters. Meaning, if there are no letters already existing for Data 1 than the next child data created would be Data 1A. If child data already existed, say A,B, and C, then the next child data for this would be Data 1D. Thanks in advance!
|
Webmaster |
08-23-2005 @ 2:06 PM |
|
|
Administrator
Posts: 4533
Joined: Jan 2002
|
How are you keeping track of what is being used or not (letter wise?)
Pablo Varando Chief Software Architect EasyCFM.COM, LLC. 904.483.1457\\ mobile webmaster@easycfm.com\\email
|
jaco5md |
08-23-2005 @ 2:11 PM |
|
|
Senior Member
Posts: 492
Joined: Jul 2005
|
Database Field like below. The Main Table: ID The Child Table: ID ChildID
|
jaco5md |
08-23-2005 @ 2:54 PM |
|
|
Senior Member
Posts: 492
Joined: Jul 2005
|
I can get a loop to display the existing data but how can I increment that to the next letter using this:
<cfset VarID = "C">
<cfloop list="A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z" index="ChildVarID"> <cfif VarID IS "C"> <cfset ChildVarID = VarID> <cfoutput>#ChildVarID#</cfoutput><cfbreak> </cfif> </cfloop>
Using this will display "C". But I want it to go to D.
This message was edited by jaco5md on 8-23-05 @ 2:54 PM
|
Webmaster |
08-23-2005 @ 2:58 PM |
|
|
Administrator
Posts: 4533
Joined: Jan 2002
|
Sorry, I am having a hard time following the procedure or the reasoning for using that... Can you explain (higher level) what yo uare trying to achieve... are you trying to create a tree? Users Pablo John Ray something along those lines? See, what I am NOT following is the "A", "B", "C" thing... Also, why are you looping through a list of letters (alphabet) for a single location? Explain a little more in detail (please) what the general idea behind this is and what you are trying to get to in the end. (Posting some code might help too )~ Pablo Varando Chief Software Architect EasyCFM.COM, LLC. 904.483.1457\\ mobile webmaster@easycfm.com\\email
This message was edited by Webmaster on 8-23-05 @ 2:58 PM
|
jaco5md |
08-23-2005 @ 3:39 PM |
|
|
Senior Member
Posts: 492
Joined: Jul 2005
|
Sorry about that, I was just trying different things. OK, Page1.cfm creates an issue with an ID of 1 and then gets redirected to page2.cfm to create a child issue. Now I need to create the ChildID of ID 1, which is going to be a letter (a-z). If no ChildID exists then the ChildID would be A. If ID 1 already has 3 ChildIDs (1A, 1B, 1C) then I need code that will automatically assign it the next available letter "D". I hope that helps.
|
jfill |
08-23-2005 @ 5:23 PM |
|
|
Senior Member
Posts: 446
Joined: Apr 2004
|
You could try something like this.
<!--- issue ID that is passed from Page1.cfm ---> <cfset variables.mainIssueID = form.mainIssueID>
<!--- set the child issue list ---> <cfset variables.childList = "A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z">
<cfquery name="mainIssue"> select ID, ChildID from childTable WHERE id = <cfqueryparam value="#variables.mainIssueID#" cfsqltype="cf_sql_integer" null="no" /> </cfquery>
<!--- check to see if the main issue already has atleast one child ---> <cfif mainIssue.recordCount> <!--- there are mainIssue.recordCount child records in the table, add one and get the next record ---> <cfset variables.nextChildID = val(mainIssue.recordCount) + 1> <cfset variables.childIssue = listGetAt(variables.childList,variables.nextChildID)> <cfelse> <!--- there are no child issues, so create the first one ---> <cfset variables.childIssue = listGetAt(variables.childList,1)> </cfif> <!--- now insert the new child issue into the database ---> <cfquery name="mainIssue"> INSERT INTO childTable (ID,childID) VALUES (<cfqueryparam value="#variables.mainIssueID#" cfsqltype="cf_sql_integer" null="no" />, <cfqueryparam value="#variables.childIssue#" cfsqltype="cf_sql_integer" null="no" />) </cfquery>
This message was edited by jfill on 8-23-05 @ 5:28 PM
|
jaco5md |
08-24-2005 @ 8:43 AM |
|
|
Senior Member
Posts: 492
Joined: Jul 2005
|
Thanks Jill. Will this work if I am using an Access DB?
|
jfill |
08-24-2005 @ 9:16 AM |
|
|
Senior Member
Posts: 446
Joined: Apr 2004
|
Sure it will. You will need to change the names of your tables from the code I gave you to match your db. Also you might need to add a username and password to the cfquery tag. I have not tested this, I just put it together as an idea of what you could do. Play with it and see what you get.
|
jaco5md |
08-24-2005 @ 4:31 PM |
|
|
Senior Member
Posts: 492
Joined: Jul 2005
|
Jill, thank you so much for what you did. It works great!!
This message was edited by jaco5md on 8-24-05 @ 4:30 PM
|