ColdFusion Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming Languages - MoreColdFusion Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old September 20th, 2005, 03:18 PM
Caden Caden is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 272 Caden User rank is Private First Class (20 - 50 Reputation Level)Caden User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 7 h 8 m 8 sec
Reputation Power: 4
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

Reply With Quote
  #2  
Old September 20th, 2005, 07:09 PM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,661 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 14 h 23 m 22 sec
Reputation Power: 53
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

Reply With Quote
  #3  
Old September 20th, 2005, 10:49 PM
Caden Caden is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 272 Caden User rank is Private First Class (20 - 50 Reputation Level)Caden User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 7 h 8 m 8 sec
Reputation Power: 4
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

Reply With Quote
  #4  
Old September 21st, 2005, 08:55 AM
Caden Caden is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 272 Caden User rank is Private First Class (20 - 50 Reputation Level)Caden User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 7 h 8 m 8 sec
Reputation Power: 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?

Reply With Quote
  #5  
Old September 21st, 2005, 09:17 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,661 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 14 h 23 m 22 sec
Reputation Power: 53
Quote:
Originally Posted by Caden
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.
But again, this is *exactly* what a database is designed to do. You say "create a whole new table" as if this was actually any work to do, or as if a database with fewer tables is somehow preferred. It would be a table with 2 columns...a foreign key and the value you want to store. Creating this table would take you 10 seconds. And then it would be done. This is database normalization and unless there is a significant performance reason you almost always want to normalize as far as is practical.

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.

Reply With Quote
  #6  
Old September 21st, 2005, 09:30 AM
Caden Caden is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2005
Posts: 272 Caden User rank is Private First Class (20 - 50 Reputation Level)Caden User rank is Private First Class (20 - 50 Reputation Level) 
Time spent in forums: 2 Days 7 h 8 m 8 sec
Reputation Power: 4
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...

Reply With Quote
  #7  
Old September 21st, 2005, 10:42 AM
kiteless kiteless is offline
Moderator
Dev Shed Expert (3500 - 3999 posts)
 
Join Date: Jun 2002
Location: Raleigh, NC
Posts: 3,661 kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level)kiteless User rank is Sergeant Major (2000 - 5000 Reputation Level) 
Time spent in forums: 1 Week 4 Days 14 h 23 m 22 sec
Reputation Power: 53
This isn't going to work:

,form.textbox#boxnumber#

Try this:

#form['testbox#boxnumber#']#

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming Languages - MoreColdFusion Development > Dynamic Lists


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway