On Wednesday, Jul 9, 2003, at 13:13 US/Pacific, Hagan, Ryan Mr (Contractor ACI) wrote: > function list_categories( $parentId, $level ) {
<cffunction name="list_categories"> <cfargument name="parentId" type="numeric"> <cfargument name="level" type="numeric"> > global $database, $connection; > $numSpaces = 5; <cfset var numSpaces = 5> <cfset var result = 0> <cfset var spaces = 0> <cfset var spaceString = ""> > $query = "SELECT * FROM myTable WHERE parentId = " . $parentId; > $result = mysql_query($query, $connection); <cfquery datasource="#request.connection#" name="result"> SELECT * FROM myTable WHERE parentId = #arguments.parentId# </cfquery> > while( $row = mysql_fetch_assoc( $result ) ) { <cfloop query="result"> > // output spaces for proper indentation > for ( $spaces=0; $spaces<=($level*$numSpaces); $spaces++ ) <cfloop index="spaces" from="1" to="#level * numSpaces#"> > echo ' '; <cfset spaceString = spaceString & " "> </cfloop> <!--- output this category prefixed by spaceString ---> > echo '<br>\n'; <br /> > list_categories( $row["itemId"], $level+1 ); <cfset list_categories( result.itemId, level+1 )> > } </cfloop> > } > > // list entire table in tree format > list_categories( 0, 0 ); <cfset list_categories( 0, 0 )> > I'd love to be able to write this code in CFMX, but for several > reasons, > it's just not possible. See above. Untested but it should be pretty close. > First and foremost, we can't run queries inside of <cfscript> tags. > Bummer. So write the function using tags as above. > Second, even if the query issue were resolved (and if you've got ideas > for > work-arounds, I'd love to hear them), you've now got variable scope > issues. Not a problem - see above. > A variable declared in a CFMX page is global (correct me if I'm wrong) > to > the entire page, even inside of functions. Yes, it's in the "variables" scope. The solution is to use "var" to declare local variables in a function. > In other words, unlike PHP, CFMX > functions do not have their own scope separate from the rest of the > page Wrong - see above. Sean A Corfield -- http://www.corfield.org/blog/ "If you're not annoying somebody, you're not really alive." -- Margaret Atwood ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| Archives: http://www.houseoffusion.com/cf_lists/index.cfm?forumid=4 Subscription: http://www.houseoffusion.com/cf_lists/index.cfm?method=subscribe&forumid=4 FAQ: http://www.thenetprofits.co.uk/coldfusion/faq Signup for the Fusion Authority news alert and keep up with the latest news in ColdFusion and related topics. http://www.fusionauthority.com/signup.cfm Unsubscribe: http://www.houseoffusion.com/cf_lists/unsubscribe.cfm?user=89.70.4