[thelist] CF: Values transposition. Too ugly, needs a face lift.

Jeff Howden jeff at jeffhowden.com
Tue Aug 2 20:47:45 CDT 2005


Frank,

><><><><><><><><><><><><><><><><><><><><><><><><><><><><><
> From: Frank
> 
> I've written a custom tag that builds a tree based on
> values in my database. It uses the typical parent/child
> scheme of record_id (parent) and parent_record (child).
> 
> Because the tag uses attributes that refers to the db
> itself (such as db_parent_field, db_child_field) I end
> up using a very inefficient manner of getting at the
> value of said variables as such:
> 
> <cfset parent_field_value =
>        Evaluate("get_current_items." & db_parent_field)>
> <cfset parent_field_value = 
>        Evaluate(parent_field_value)>
><><><><><><><><><><><><><><><><><><><><><><><><><><><><><

Ack.  Evaluate() is evil.  You knew I'd say that though.

Bracket notation is your friend (this example assumes you're inside a query
loop):

<cfscript>
  parent_field_value = get_current_items[db_parent_field][currentrow];
</cfscript>

That doesn't even begin to address the bigger problems surrounding
hierarchical data stored an the typical parent/child schema.  It's far too
cumbersome on both the management *and* retrieval sides to use on the web.
There are various limitations with the modified preorder tree traversal
method as well, so be careful.

Personally, I'd recommend something entirely different:

http://www.morgankelsey.com/code/multi-threaded_board/

Enjoy,

 [>] Jeff Howden
     jeff at jeffhowden.com
     http://jeffhowden.com/



More information about the thelist mailing list