cf coder wrote:

> Hi Robert,
>
> apologies for causing any confusion. I was asked to present the data
> stored in the database table column in a certain way. Historically
> data stored in this column is as under:
>
> timestamp
> comments
>
> EX:
>
> *** 05/12/2003 09:52:10 USER1 ***
> closing if fixed - awaitng response from User2
>
> I was asked to get rid of the stars and reorder the timestamp to
> something like this:
>
> USER1 05/12/2003 09:52:10
> (Username, Date, Time)
>
> All comments (timestamps) added henceforth will be added in this fashion.
> I hope this gives you a better understanding. The solution Pascal
> provided does just that and it does the job for me.
>
> Best Regards,
> cfcoder
>
Ummm.... This thread has been going on and on and I can't help but feel
that this is overcomplicated this somewhat...

Your comment is a string with a number of lines in it. Your date/time
stamp is denoted by being started and finished with 3 asterisks.  
Wouldn't this be simpler?

<cfscript>
//create new query for this record's Comment/LogField entry
thisLogQuery = QueryNew();
QueryAddColumn(thisLogQuery,"UserID");
QueryAddColumn(thisLogQuery,"logDate");
QueryAddColumn(thisLogQuery,"logTime");
QueryAddColumn(thisLogQuery,"Comment");

for (i=1;i lTE ListLen(LogField,chr(13)); i=i+1) {
   thisLogLine = trim(ListGetAt(LogField,i));
   if (ListFirst(thisLogLine," ") EQ "***") {
       // new date stamp, new row
       QueryAddRow(thisLogQuery);
       if (IsDate(ListGetAt(thisLogLine,2," ")){
          // Check for old format with date first
           QuerySetCell(thisLogQuery,"logDate",ListGetAt(thisLogLine,2,"
"));
           QuerySetCell(thisLogQuery,"logTime",ListGetAt(thisLogLine,3,"
"));
           QuerySetCell(thisLogQuery,"UserID",ListGetAt(thisLogLine,4," "));
       } else {
          // otherwise use new format
           QuerySetCell(thisLogQuery,"UserID",ListGetAt(thisLogLine,2," "));
           QuerySetCell(thisLogQuery,"logDate",ListGetAt(thisLogLine,3,"
"));
           QuerySetCell(thisLogQuery,"logTime",ListGetAt(thisLogLine,4,"
"));
       }
    } else
QuerySetCell(thisLogQuery,"Comment",thisLogQuery.Comment[recordcount]&chr(13)&thisLogLine);
}
</cfscript>

You end up with a nice wee query of all the log entries for a record,
new and old user/date/time stamps are handled, handles comments with
multiple lines, it'll be easier to display the contents of the query, it
should work in both CF5 and CFMX and anyone looking at it later can read
the code!

FOOT NOTE:  I just typed this in off the top of my head.  I haven't run
the code, or checked it in anyway.  You may need to tweak it or it might
need minor debugging..

Regards

Stephen
[Todays Threads] [This Message] [Subscription] [Fast Unsubscribe] [User Settings]

Reply via email to