|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| ||||||||||||||||||||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi I am new to Coldfusion.
Goal: 1. Display pipe delimited data from a text file to a table 2. Create edit function for each record 3. Pass the selected record to a form **STUCK** HELP ME! 4. Write to the text file by submitting form. I can do this with database but text files is a whole new thing for me. I'm stuck on populating the form... help... Thanks. Here's my code: Code:
<!---file location--->
<cfset textfile = "/fullpath/data.txt">
<!---linefeed character and carriage return character--->
<cfset crlf = Chr(10) & Chr(13)>
<!---save variable at starting point --->
<cfset rowID = 0>
<!---text existence of a parameter, if doesnot exist, continue regardless--->
<cfparam name="edit" default="">
<!---Read file--->
<cffile action="read" variable="Message" file="#textfile#">
<!--- Set each line in variable--->
<cfset line="#Message#">
<!--- Set array variable, delimiter--->
<cfset arr = ListToArray(line, '|', true)>
<cfif edit EQ "yes">
<h1>Employee Data</h1>
<p><a href="./edit.cfm">Back to Edit Page list</a></p>
<table>
<form action="edit.cgi" method=post>
<tr>
<td>Code:</td>
<td><input type=text size=7 maxlength=7 name=code value="<cfoutput>#arr[1]#</cfoutput>"></td>
</tr>
<tr>
<td>Name:</td>
<td><input type=text size=50 maxlength=50 name=name value="<cfoutput>#arr[2]#</cfoutput>"></td>
</tr>
<tr>
<td>Title:</td>
<td><textarea rows=4 cols=50 name=objective wrap=soft><cfoutput>#arr[3]#</cfoutput></textarea></td></tr>
<tr>
<td colspan="2" align="right"><input type=submit value="Submit Changes" name="Submit Changes"></td>
</tr>
</form>
</table>
<cfelse>
<!---Output the Table headings --->
<h1>Employee Data - Edit Page</h1>
<table border="1">
<tr align="left" class="tableHeadingEdit">
<th valign="top">Code</th>
<th valign="top">Name</th>
<th valign="top">Title</th>
</tr>
<!---Iterate, read the file data by line ending--->
<cfloop index="message" file="#textfile#">
<!--- Count row --->
<cfset rowID = rowID + 1>
<!--- Set each line in variable --->
<cfset list="#message#">
<!--- Set array variable, delimiter--->
<cfset arr = ListToArray(list, '|', true)>
<!--- Set array names for each field --->
<cfset fieldNameArray = ArrayNew(1)>
<cfset fieldNameArray[1] = "code">
<cfset fieldNameArray[2] = "name">
<cfset fieldNameArray[3] = "title">
<cfset fieldNameArray[4] = "">
<tr>
<!--- Set colID to start at 0 for count --->
<cfset colID = 0>
<!--- Loop through each "message" in cells for a row--->
<cfloop from="1" to="#arraylen(arr)#" index="i">
<!--- Set colID to count in increments of 1 --->
<cfset colID = colID + 1>
<!--- Output each iteration of delimited values in cells across all fields --->
<cfoutput>
<td class="rowText" name="#fieldNameArray[colID]##rowID#">#arr[variables.i]#</td>
</cfoutput>
</cfloop>
<!--- Edit buttons --->
<cfset arrURL = ListToArray(list, '|', true)>
<cfoutput>
<td align="center"><a href="?edit=yes&code=#arrURL[1]#">edit</a></td>
</cfoutput>
</tr>
</cfloop>
</table><br/>
</cfif>
Text file: Code:
SOF|Steve|Software Engineer| ADM|Mary|Administrator| Last edited by electron_89 : September 10th, 2009 at 07:38 PM. Reason: To be more clear |
|
#2
|
|||
|
|||
|
It sort of works but only populates with the first record data only regardless of which record is clicked to edit so I have a problem with figuring out how to tell it to populate according what is selected...
Last edited by electron_89 : September 10th, 2009 at 12:31 PM. |
|
#3
|
||||
|
||||
|
When anyone gives me a text file that holds data (or any type of file for that matter) The first thing I do is dump it to a table and just use that instead.
__________________
Three gigs for the secretaries fair Seven gigs for the system source Nine gigs for the coders in smoky lairs One disk to rule them all, one disk to bind them One disk to hold the files, and in the darkness grind'em --------------------------------------------------- It is by caffeine alone that I set my mind in motion. It is by the beans of Java, that my thoughts acquire speed. The hand acquire shakes; the shakes become a warning. It is by caffeine alone that I set my mind in motion. |
|
#4
|
|||
|
|||
|
I understand. Believe me, I would if I could. However, I am purposely told to do it this way by the boss.
|
|
#5
|
|||
|
|||
|
If you're on CF8 you can just loop over the file:
<cfloop file="c:\temp\simplefile.txt" index="line"> <cfoutput>#line#</cfoutput><br> </cfloop> |
|
#6
|
|||
|
|||
|
Quote:
That has been done as you can see in my code. I am stuck on populating a selected row to a form and writing that update form back to the text file... Last edited by electron_89 : September 10th, 2009 at 07:22 PM. |
|
#7
|
|||
|
|||
|
Ah I just saw the CFFile in the first section of the code and assumed that was how you were doing it.
Can't you just pass the line number of the line being edited, and then use that on the edit screen to determine which line's data to populate the form with, and do the same when saving it so you know which line to update? |
|
#8
|
|||
|
|||
|
Quote:
Well, I hope they are not planning to "add" lines as well as "edit". That might produce some ... interesting results. |
|
#9
|
|||
|
|||
|
Not if lines are added at the end of the file. Deleting would be an issue though, if the file changed between the time the list was viewed and the edit was called.
The alternative is to pass some other unique identifier that the edit page can use to locate the correct line to edit. Any way you cut this, using a text file as a data repository is an absolutely terrible idea. |
|
#10
|
|||
|
|||
|
Yes, you are right. I meant to say add/delete (ie full manipulation)
Quote:
Yep. I agree 100%. |
|
#11
|
|||
|
|||
|
well that doesn't solve my problem...
|
|
#12
|
|||
|
|||
|
Quote:
Did you look at the suggestions kiteless made in his last posts? Like it or not, there is no avoiding the fact that this is a bad idea and you may run into further issues. But it is something you should be aware of, so you can at least try and mitigate the damage if you are stuck with this option. |
|
#13
|
|||
|
|||
|
Thanks cfSearching. Yes I am aware. I am stuck with this option.
Please see my new thread: http://forums.devshed.com/coldfusion-development-84/text-file-to-2d-array-641319.html |
|
#14
|
||||
|
||||
|
Did you ever look at the last two comments kiteless made in this thread?
Quote:
Quote:
|
![]() |
| Viewing: Dev Shed Forums > Programming Languages - More > ColdFusion Development > Text files, Arrays, Forms, editing, updating, and deleting |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|
|