{"id":277,"date":"2010-07-07T09:48:09","date_gmt":"2010-07-07T13:48:09","guid":{"rendered":"http:\/\/erics-test-lab.com\/?p=277"},"modified":"2010-07-07T09:48:09","modified_gmt":"2010-07-07T13:48:09","slug":"looping-over-column-names","status":"publish","type":"post","link":"https:\/\/www.esearing.com\/v2010\/2010\/07\/looping-over-column-names\/","title":{"rendered":"looping over column names"},"content":{"rendered":"<p>Occasionally I just need a dump of results from a query columns and values. I have two methods for this.<\/p>\n<p>The SQL (cfquery name=&#8221;myquery&#8221;)<br \/>\n<code>Select TOP 1 * from contacts<br \/>\n&nbsp;<br \/>\nThe simple method allows me to output the column names and the values in alphabetical order. The evaluate(column) is what displays the values.<br \/>\n&lt;cfoutput query=\"myquery\"><br \/>\n&lt; cfloop list=\"#myquery.ColumnName#\" index=\"column\"><br \/>\n#column#: #Evaluate(column)# &lt;br><br \/>\n&lt;\/cfloop><br \/>\n&nbsp;<br \/>\nColumn name list Yields: address, city, contact_id, email, fname, lname, phone, state, zipcode.  Which while useful is a bit confusing for output.<br \/>\n&nbsp;<br \/>\nIf I want my columns output in a particular order I merely replace the \"list=#myquery.ColumnName#\" with  a list of the columns I want to display in the order I want to display them. The rest of the code is the same.<br \/>\n&nbsp;<br \/>\n&lt; cfloop list=\"fname, lname, address, city, state, zipcode, phone\" index=\"column\"><br \/>\n&nbsp;<br \/>\nI can even suppress data that is blank or meets other criteria within the loop.<br \/>\n&lt;cfif #len(EVALUATE(column))# gt 1><span class=\"titlelabel\">#column#:<\/span><br \/>\n &nbsp;&nbsp;&nbsp;&lt;cfif isdate(EVALUATE(column))><br \/>\n &nbsp;&nbsp;&nbsp;#dateformat(EVALUATE(column), \"mm\/dd\/yyyy\")#<br \/>\n &nbsp;&nbsp;&nbsp;&lt;cfelse><br \/>\n &nbsp;&nbsp;&nbsp;#EVALUATE(column)#<br \/>\n &nbsp;&nbsp;&nbsp;&lt;\/cfif><br \/>\n&lt;\/cfif><\/code><\/p>\n","protected":false},"excerpt":{"rendered":"<p>Occasionally I just need a dump of results from a query columns and values. I have two methods for this. The SQL (cfquery name=&#8221;myquery&#8221;) Select TOP 1 * from contacts &nbsp; The simple method allows me to output the column &hellip; <a href=\"https:\/\/www.esearing.com\/v2010\/2010\/07\/looping-over-column-names\/\">Continue reading <span class=\"meta-nav\">&rarr;<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5],"tags":[],"class_list":["post-277","post","type-post","status-publish","format-standard","hentry","category-code"],"_links":{"self":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/277","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/comments?post=277"}],"version-history":[{"count":0,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/posts\/277\/revisions"}],"wp:attachment":[{"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/media?parent=277"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/categories?post=277"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.esearing.com\/v2010\/wp-json\/wp\/v2\/tags?post=277"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}