?
Solved

Real quick.

Posted on 2003-03-31
10
Medium Priority
?
124 Views
Last Modified: 2013-12-24
got a form that ask how many rows to return in the next form. (ex 5)

upon submit the new form has 5 rows of the same fields.

my problem lies here

upon submiting the form that now has 5 rows with the same field names, iwould like to do the following,

1.  show the user what is about to be inserted like this.

yourname >> your>> other>> fields
yourname >> your>> other>> fields
yourname >> your>> other>> fields
yourname >> your>> other>> fields
yourname >> your>> other>> fields

it is showing up like this:
yourname, your, other, fields,yourname, your, other, fields,yourname, your, other, fields,yourname, your, other, fields,yourname, your, other, fields

2.  I would then insert those records into the db 1 row per db record.

any help would be greatly appreciated..
0
Comment
Question by:jriver12
10 Comments
 
LVL 4

Expert Comment

by:crosenblum
ID: 8240038
What data would be used to populate that breadcrumb?

I am not sure what you are trying to do.

0
 

Author Comment

by:jriver12
ID: 8240101
example:

howmany page:

How many rows do you need for the data >>5>> submit>>


Return page
now has 5 rows containing the following fields:
(all named the same)
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<

Now I know that on submit being that these fields are all named the same therefore they will be displayed as a list.

What I am trying to figure out is how to break the list at the end of the last item in that row and then insert those rows into the db  as individual rows.

thanks

hope that this cleared it up for you.
0
 
LVL 8

Accepted Solution

by:
TallerMike earned 600 total points
ID: 8240133
In reality, you should NEVER name inputs the same name UNLESS they are checkboxes or radio options. Text inputs should ALWAYS have a unique name within the form.

With that said, one option is to take that row number and use it to create unique names for the inputs like so:

<input type="hidden" name="numberOfRows" value="#form.numberOfRows#">
<cfloop from="1" to="#form.numberOfRows#" index="rowCount">
  <input type="text" name="yourname_#rowCount#">
  <input type="text" name="your_#rowCount#">
  <input type="text" name="other_#rowCount#">
  <input type="text" name="fields_#rowCount#">
</cfloop>

******************************************************************************************
******************************************************************************************

Then your processing page should loop through the numberOfRows variable and evaluate the input values, SOMETHING (but maybe not exactly) like so:

<cfloop from="1" to="#form.numberOfRows#" index="rowCount">
<cfscript>
  yourname = Evaluate("yourname_#rowCount#");
  your = Evaluate("your_#rowCount#");
  other = Evaluate("other_#rowCount#");
  fields = Evaluate("fields_#rowCount#");
</cfscript>
*** Do your output / update within this loop ***
</cfloop>
0
[Webinar On Demand] Database Backup and Recovery

Does your company store data on premises, off site, in the cloud, or a combination of these? If you answered “yes”, you need a data backup recovery plan that fits each and every platform. Watch now as as Percona teaches us how to build agile data backup recovery plan.

 

Author Comment

by:jriver12
ID: 8240156
example:

howmany page:

How many rows do you need for the data >>5>> submit>>


Return page
now has 5 rows containing the following fields:
(all named the same)
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<

Now I know that on submit being that these fields are all named the same therefore they will be displayed as a list.

What I am trying to figure out is how to break the list at the end of the last item in that row and then insert those rows into the db  as individual rows.

thanks

hope that this cleared it up for you.
0
 
LVL 3

Expert Comment

by:cdillon
ID: 8240183
Here is my coding interpretation of what you are trying to do. You will need to modify it to fit your case:

<cfquery name="myquery" datasource="#dsn#">
  select * from originaltable
</cfquery>

<cfloop index="counter" from="1" to="#form.number_selected#">
#myquery.Name#&gt;&gt;#myquery.Company#&gt;&gt; #myquery.Ceo#&gt;&gt;#myquery.Date#&gt;&gt;#myquery.somethingelse#&lt;&lt;
</cfloop>

<cfloop index="counter" from="1" to="#form.number_selected#">

<cfquery name="copies" datasource="#dsn#">
   insert into destinationtable(name,company,ceo,date,somethingelse) values('#myquery.Name#','#myquery.Company#', '#myquery.Ceo#','#myquery.Date#','#myquery.somethingelse#')
</cfquery>

</cfloop>
0
 

Author Comment

by:jriver12
ID: 8240260
example:

howmany page:

How many rows do you need for the data >>5>> submit>>


Return page
now has 5 rows containing the following fields:
(all named the same)
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<
Name>>Company>> Ceo>>Date>>somethingelse<<

Now I know that on submit being that these fields are all named the same therefore they will be displayed as a list.

What I am trying to figure out is how to break the list at the end of the last item in that row and then insert those rows into the db  as individual rows.

thanks

hope that this cleared it up for you.
0
 
LVL 8

Expert Comment

by:TallerMike
ID: 8240331
jriver12, please do NOT refresh the page. Please use the "Reload This Question" link at the top of the left navigation menu. When you refresh, you repost your last comment.
0
 
LVL 10

Expert Comment

by:substand
ID: 8240392
on the submit page where you display all the fields of the same name, make sure to include:

<input type="hidden" name="num_selected" value="#form.num_selected#">

of course, replacing form.num_selected with whatever you named the field in the first form.

on the submit page where you INSERT the data you would do:

<cfloop from="1" to="#form.num_selected#" index="cnt">

<cfset curRowIndex=(cnt-1)*5>

<cfquery name="insert" datasource="#datasourceName#">
insert into tablename (name, company, ceo, date, somethingelse) values
(#listgetat(form.field_that_is_named_the_same, curRowIndex+1)#,#listgetat(form.field_that_is_named_the_same, curRowIndex+2)#,#listgetat(form.field_that_is_named_the_same, curRowIndex+3)#,#listgetat(form.field_that_is_named_the_same, curRowIndex+4)#,#listgetat(form.field_that_is_named_the_same, curRowIndex+5)#)

</cfquery>

</cfloop>

you better hope the user doesn't use a comma in thier response though, as this will screw everything up and there is no way to fix it.  Personally, I would use TallerMike's approach- as it won't get broken by user input.
0
 
LVL 11

Expert Comment

by:hart
ID: 8243530
i would suggest that you go with Tallermikes suggestion,

but if u r going to continue with yours.
then all you have to do is this.. or forget it.

i strongly feel u should go with Tallermikes suggestion..

Regards
Hart(harish)
0
 

Author Comment

by:jriver12
ID: 8255224
Thanks, I apologize for taking so long.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: kevp75
Hey folks, 'bout time for me to come around with a little tip. Thanks to IIS 7.5 Extensions and Microsoft (well... really Windows 8, and IIS 8 I guess...), we can now prime our Application Pools, when IIS starts. Now, though it would be nice t…
Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Whether it be Exchange Server Crash Issues, Dirty Shutdown Errors or Failed to mount error, Stellar Phoenix Mailbox Exchange Recovery has always got your back. With the help of its easy to understand user interface and 3 simple steps recovery proced…
Suggested Courses
Course of the Month12 days, 21 hours left to enroll

579 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question