Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Looping Through Query Results

Status
Not open for further replies.

scripter73

Programmer
Apr 18, 2001
421
US
Hi,

I used to know how to do this before I left CF for about a year.

Hope this is a simple question.

I have a query.

Code:
<cfquery name="get_cust" datasource="customers" maxrows=20>

select 
	custid,
        contactid,
	custname_contact,
	firstname,
	lastname,
	type,
	workphone,
	address,
	email,
	city,
	state,
	zip
from customer_contact

</cfquery>

I'm trying to output each data record on one line. (I'll add in formatting to separate data later. I can do that.)
But for now, I just want to print the record results for every record on its own line.

Here's what I have so far:
Code:
<cfoutput query="get_cust">
  <cfloop index="i" list="get_cust.columnlist">
		#evaluate(get_cust.currentrow)#<br>
  </cfloop> 
</cfoutput>
But this only gets me the first value in every column, and I want to get every value in the column and then separate them with tabs.

Thanks in advance for any help.

scripter73


Change Your Thinking, Change Your Life.
 
whats the point of looping? Are the returned columns dynamic?
Code:
<cfoutput query="get_cust">
#custid#,#contactid#,#custname_contact#,#firstname#,etc..<br>
</cfoutput>
i think the tab character is chr(9)


=========================================
I have not failed. I've just found 10,000 ways that won't work.
Thomas A. Edison
 
<cfset ColumnArray = ListToArray(get_cust.columnlist)>
<p>
<cfoutput query="get_cust">
#get_cust.currentrow# --
<cfloop index="i" from="1"
to="#ArrayLen(ColumnArray)#">
#chr(9)##evaluate("get_cust."&ColumnArray)#
</cfloop><br />
</cfoutput>
</p>

rudy | r937.com | Ask the Expert | Premium SQL Articles
SQL for Database-Driven Web Sites (course starts January 9 2005)
 
Thanks for your suggestions.

Right, NorthStarDA, I want them to be dynamic where I don't have to specifically reference each one.

r937, it did grab all of the fields. I'm really trying to import these fields into Excel. Your suggestion worked, great. I just have to figure out how to get all of the results entered on one Excel row line. Right now, each data element is being entered on every row.

Thanks again.
scripter73


Change Your Thinking, Change Your Life.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top