Any assistance would be appreciated 🙂
I connected my CF2018 to my mariaDB server:
Actions | Data Source Name | Driver | Status | |||
---|---|---|---|---|---|---|
|
||||||
|
||||||
|
rhce | MySQL | OK |
But, I’m getting below output:
SELECT sno, firstname, lastname, city, country, age FROM scientists
Sno | FirstName | LastName | City | Country | Age |
---|---|---|---|---|---|
#sno# | #firstname# | #lastname# | #city# | #country# | #age# |
From my RHEL7 server, I can pull the data:
MariaDB [rhce]> select * from scientists;
+——+———–+————+————-+———+——+
| Sno | Firstname | LastName | City | Country | Age |
+——+———–+————+————-+———+——+
| 1 | Albert | Einstein | Ulm | Germany | 76 |
| 2 | Isaac | Newton | Woolsthorpe | UK | 76 |
| 3 | Marie | Curie | Warsaw | Poland | 67 |
| 4 | Galileo | Galilei | Pisa | Italy | 78 |
| 5 | Thomas | Edison | Milan | USA | 84 |
| 6 | Alexander | Bell | Edinburg | UK | 75 |
| 7 | Louis | Pasteur | Dole | France | 73 |
| 8 | Nicolaus | Copernicus | Toruri | Poland | 70 |
| 9 | James | Maxwell | Edinburg | UK | 48 |
| 10 | Pierre | Curie | Paris | France | 47 |
+——+———–+————+————-+———+——+
10 rows in set (0.000 sec)
MariaDB [rhce]>
Here’s my code:
<cfquery name=”getScientists” datasource=”rhce”>
SELECT sno, firstname, lastname, city, country, age
FROM scientists
</cfquery>
<html>
<head>
<title>Using cfoutput</title>
</head>
<body>
<table border=”1″>
<tr>
<th>Sno</th>
<th>FirstName</th>
<th>LastName</th>
<th>City</th>
<th>Country</th>
<th>Age</th>
</tr>
<cfoutput query=”getScientists”>
<tr>
<td>#sno#</td>
<td>#firstname#</td>
<td>#lastname#</td>
<td>#city#</td>
<td>#country#</td>
<td>#age#</td>
</tr>
</cfoutput>
</table>
</body>
</html>
Marty–
As Charlie and Priyank said, it sounds like you need to verify that CF is actually running on your web server. To help debug that problem, I create the following test file in the root of my webserver (usually name the file ‘test1.cfm’):
<cfset OutputStr = “Hello Word”>
<cfsetting showdebugoutput = “yes”>
<html>
<head>
<title>ColdFusion Test</title>
</head>
<body>
<h1>ColdFusion Test</h1>
<p>
<cfoutput>
#OutputStr#
</cfoutput>
</p>
</body>
</html>
Then use your browser to load the page (eg, http://localhost/test1.cfm or http://localhost:8500/test1.cfm or something similar depending on your configuration). If you see ‘Hello World’ CF is running and all is good. If you see ‘#OutputStr#’ or other stuff, CF isn’t processing your page.
Once you verify that CF is running, here’s another tip for you. In your code, right after the </cfquery> tag, use CFDUMP to show the results of your DB query:
<cfdump var=”#getScientists#” expand=”yes” output=”browser”>
This will show you the results of the query without having to deal with cfloop or creating table elements. The cfdump tag can really be a time-saver to debug data issues, especially with complex data like query results. More info here. [Note: if you’re using cfscript syntax, it’s writeDump() instead of cfdump. ]
Hope that helps,
Mark
Mark, what you say is helpful (or I hope it will be for Marty), and in the same spirit of helpfulness I will point out for both your sakes that your code samples could be reduced considerably. The first could be done in just 2 lines as:
<cfset OutputStr = “Hello Word”> <cfoutput>#OutputStr#</cfoutput>
All the HTML really is unnecessary (as is the cfsetting, since it has no impact on the code that’s running). And your offered CFDUMP could be done with just the one attribute:Â
<cfdump var=”#getScientists#”>
since the expand and output attribute values you indicated are the defaults.
Marty, as Charlie mentioned that it is quite possible that CFML is not running at all. Can you please let us know where you are putting your code?
- Webserver(IIS/Apache),
- Or In ColdFusion’s webroot – \cf-root\cfusion\wwwroot\
If you are putting this in IIS/Apache webroot, do you have the connector for ColdFusion?
Marty, you don’t clarify it, but is this the first CF page you are running? If so, your problem has nothing to do with your sql or datasource (despite your title).
Instead, the output you show is indicating that the CFML is not running at all. Instead, if you do a “view source” on your page’s output (using the browser menu or a right-click in the page content), you will see that you actually SEE your CFML underlying your page. The CFML is not running.
So show us first the URL you are using to browse your page. It may be simply that you are not requesting the URL via a web server (CF’s or another). Or it may be that your web server has a configuration problem so that the URL is not being passed into CF to execute the CFML.
Hi,
I am reasonably new to Coldfusion (less than 12 months) but I would try this…
<html>
<head>
<title>Using cfoutput</title>
</head>
<body>
<table border=”1″>
<tr>
<th>Sno</th>
<th>FirstName</th>
<th>LastName</th>
<th>City</th>
<th>Country</th>
<th>Age</th>
</tr>
<cfoutput>
<cfloop query=”getScientists”>
<tr>
<td>#sno#</td>
<td>#firstname#</td>
<td>#lastname#</td>
<td>#city#</td>
<td>#country#</td>
<td>#age#</td>
</tr>
</cfloop>
</cfoutput>
</table>
</body>
</html>
You must be logged in to post a comment.