Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to enter formfields to database

Status
Not open for further replies.

8ginga8

Programmer
Dec 14, 2004
54
CA
I have about 25 formfields with names like 1:mon, 1:tue, 1:wed, 1:thu, 1:fri, 2:mon, 2:tue, 2:wed,..... 6:thu, 6:fri.

The number at the beginning is the id of the record that the field belongs to so what I need to do is strip the number off and using it as a record identifier and the mon, tue, wed, etc.. as the field in the table and update the approiate values into those fields

 
you have two lists there one is seperated with a , and the other list that uses :

loop throught the larget list, then use listFirst and listLast with the : as a delimiter.

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
That sounds good, but when I try to do a simple output it does nothing here is my code

<cfloop list="formfields" index="i">
<cfoutput>#ListLast("form:formfields", ":")# <br>
</cfoutput>
</cfloop>

Any ideas
 
when you said
<cfloop list="formfields" index="i">
you told cf the list was "formfields"
you want to tell coldfusion the list is the VALUE of formfields
Code:
<cfset formfields = "1:mon,1:tue,1:wed,1:thu,1:fri,2:mon,2:tue,2:wed,6:thu,6:fri">
<cfoutput>
<cfloop list="[b]#[/b]formfields[b]#[/b]" index = "i">
#listFirst(i, ":")# #listLast(i, ":")#
</cfloop>
</cfoutput>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
I changed the formfield names to match the table names to make things a little easier:
1:mon_avail,1:tue_avail,1:wed_avail,1:thu_avail,1:fri_avail,2:mon_avail,2:tue_avail,2:wed_avail,6:thu_avail,6:fri_avail
know I am pulling the ID from the first of the formfield and the field name from the end of the formfield, and the value as well. but my update is not working at all.

<CFLOOP COLLECTION="#form#" ITEM="myfield">
<cfset id = #listfirst(myfield, ":")#>
<cfset field = #listlast(myfield, ":")#>
<cfset value = #form[myfield]#>
<cfif #listlast(myfield, ":")# EQ "mon_avail">
<cfquery datasource="#database#">
UPDATE weekly_availability
SET mon_avail = #value#
where availability_id = #id#
</cfquery>
</cfif>
 
your value is going to end up being something like "1:tue_avail" what do you really want in the database?

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
your value is going to end up being something like "1:tue_avail" what do you really want in the database?

the 1 is the record id
tue_avail is the field
and the form value is the the value I want to update to the database
 
gotcha

<CFLOOP COLLECTION="#form#" ITEM="myfield">
<cfset id = #listfirst(myfield, ":")#>
<cfset field = #listlast(myfield, ":")#>
<cfset value = #form[myfield]#>
<cfquery datasource="#database#">
UPDATE weekly_availability
SET #field# = #value#
where availability_id = #id#
</cfquery>
</cfloop>

is "value" a number? if not you need ' around it.


We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
but you'll want to not do that if the item is "fieldNames"

Code:
<CFLOOP COLLECTION="#form#" ITEM="myfield">
   <cfif myfield neq "Fieldnames">
      <cfset id = #listfirst(myfield, ":")#>
      <cfset field = #listlast(myfield, ":")#>
      <cfset value = #form[myfield]#>
      <cfquery datasource="#database#">
         UPDATE weekly_availability
         SET #field# = #value#
         where availability_id = #id# 
      </cfquery> 
   </cfif>
</cfloop>

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
no problem, sorry for the earlier confusion.

We've heard that a million monkeys at a million keyboards could produce the complete works of Shakespeare; now, thanks to the Internet, we know that is not true.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top