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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Embedded spaces in a variable name 1

Status
Not open for further replies.

fforesite

Programmer
Dec 12, 2000
4
AU
I have a problem accessing a variable in cold fusion because the variable name contains spaces. I want to output the list of tables in a MySQL database in the following way:

<CFQUERY name=&quot;getTableNames&quot; datasource=&quot;dbname&quot;>
show tables
</CFquery>

<CFoutput query=&quot;getTableNames&quot;>
<!--- Output the tablename ---><br>
</CFoutput>

However the column name returned by the MySQL query contains spaces. The column name returned by the database is &quot;Tables in dbname&quot;.

ColdFusion won't let me access #Tables in dbname# due to the spaces. Is there anyway around this or can cold fusion access the column by some index (eg. column[0])?
 
Here's the syntax for working with fields containing spaces. The output syntax only works in CF 4.0 or above.

<cfquery name=&quot;q1&quot; datasource=&quot;test&quot;>
select &quot;field one&quot; from main
</cfquery>

<cfoutput query=&quot;q1&quot;>
#q1[&quot;field one&quot;][currentrow]# <p>
</cfoutput>

In your case, you would use.

<cfoutput query=&quot;getTableNames&quot;>
#getTableNames[&quot;Tables in dbname&quot;][currentrow]#
<p>
</cfoutput>

Good luck,
GJ
 
thanks heaps, that works fine.

couldn't find any documentation about it though.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top