|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Dynamic Lists
Man, i'm just full of questions today.
Ok, so lists. Every example of lists I find are hardcoded so... <cfset mylist="monday, tuesday,..."> My situation is weird, and i'm having a problem with it. I have a variable amount of textboxes. And what I want to do, is when I post have all of the contents of what is inside that variable amount to be put into a list. Now i'm not sure how to go about this. Perhaps I name all the text boxes the same, and then set the list to <cfset mylist=textbox1> but somehow I don't think that'll work. The second problem once this problem is figured out is after it is in the database as a nice list, when I repopulate the text boxes will the list automatically put itself into 10 different text boxes with the same name if the list is delimited by something? Any help would be great. Thanks Caden |
|
#2
|
|||
|
|||
|
You can do this just by naming each text box uniquely, like "text1", "text2", etc. Also, pass a hidden field that states how many text boxes there are. So if there were 5 text boxes, pass a hidden variable called "numberOfTextBoxes" and set it to 5. Then you can loop from 1 to 5, once for each box, and do whatever with it.
All that said, your approach is flawed. Why would you choose to take 10 form fields, combine them into a list, insert the whole list into the database, then pull it out, pull the list apart, and recreate 10 fields again? Use the relational database for what it is for. Create a separate table to store what you're trying to keep in a list. Whenever you see someone trying to store a list in a single database field, 99 times out of 100 they are not solving the real problem correctly.
__________________
Ask if you have a question, but also help answer questions that you have knowledge of! Thanks, Brian. How to Post a Question in the Forums |
|
#3
|
|||
|
|||
|
But in this case I have potentially thousands of entries which could have anywhere from 1 to 10 dates associated with them.
Not that i'm saying what you are saying is wrong, just from my perspective I look at it and say... Add a single piece of data (all be it a rather large list) into the record, or create a whole new table which could have potentially thousands of entries. Although there are less steps the computer has to go through for your method then mine, so perhaps indeed yours is a better route. I'll give it a shot tomorrow and see how it goes. Thanks |
|
#4
|
|||
|
|||
|
And in this case I imagine I can also loop making the insert into the database dynamic based on the hidden variable that is passed?
|
|
#5
|
|||
|
|||
|
Quote:
Also consider that you're really just shifting the work from the database to CF, making it CF's job to build the list, insert it, pull it out, and parse it. Another good rule of thumb is make the database do all the work you possibly can, freeing up CF to do what it does best which is serve up dynamic pages. Anyway, as I said, storing the list in one column is certainly possible and depedning on the app it might work just fine. Just pointing out that in general this is *not* the approach you want to take. |
|
#6
|
|||
|
|||
|
You're right, I think I am just assuming things that I shouldn't be, like creating another table is "work" for the server.
This is where I am at so far on a looping insert, never done this before, so I hope I don't kill anything Code:
<cfset j = #form.Arrests#>
<cfset boxnumber = 1>
<cfloop index = "LoopCount" from = "1" to = #j#>
<cfquery datasource="#dsn#" name="enterArrests">
Insert into #ClientTablePrefix#_ArrestDate
( Claimno
, AddressID
, DateofArrest
)
Values
( #form.ClaimNo#
,#form.AddressID#
,form.textbox#boxnumber#
)
</cfquery>
<cfset boxnumber = boxnumber + 1>
</cfloop>
Gonna test it now... |
|
#7
|
|||
|
|||
|
This isn't going to work:
,form.textbox#boxnumber# Try this: #form['testbox#boxnumber#']# |
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Dynamic Lists |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|