# Updating a .txt file

I'm outputting the results of a query to file.txt in JSON. The file is updated every time I click on 'submit'(form) and depending on the variables it updates the query.

Right now the table only has about 20 records and will probably increase by 2/3 new records everyday.

Is there a better way to updating the file test.txt getting the results from a query?

index.cfm:

  <cfsavecontent variable="mytest">
[
<cfoutput query="getimeline">
<cfif (getimeline.CurrentRow EQ getimeline.RecordCount)>
{"title":"#name_time#","date":"#dateformat(date_time,"mmmm d, yyyy")#"}
<cfelse>
{"title":"#name_time#","date":"#dateformat(date_time,"mmmm d, yyyy")#"},
</cfif>

</cfoutput>
]
</cfsavecontent>

<cffile action="write" file="C:test.txt"  output="#mytest#">


test.txt:

[

{"title":"New Card Ordering Process 1","date":"December 28, 2015"},

]


I don't know sqat about , but it seems you could eliminate some duplication:

<cfsavecontent variable="mytest">
[
<cfoutput query="getimeline">
{"title":"#name_time#","date":"#dateformat(date_time,"mmmm d, yyyy")#"}<cfif (getimeline.CurrentRow NEQ getimeline.RecordCount)>,</cfif>
</cfoutput>
]
</cfsavecontent>

<cffile action="write" file="C:test.txt"  output="#mytest#">


If you don't mind that the comma will get placed on the next line, then you can use this more readable writing style:

<cfsavecontent variable="mytest">
[
<cfoutput query="getimeline">
{"title":"#name_time#","date":"#dateformat(date_time,"mmmm d, yyyy")#"}
<cfif (getimeline.CurrentRow NEQ getimeline.RecordCount)>,</cfif>
</cfoutput>
]
</cfsavecontent>

<cffile action="write" file="C:test.txt"  output="#mytest#">