Calculate and Display Disk Usage - coldfusion

Using CF8, I want to produce a graph that displays the disk usage, in megabytes, per client. The clients are the directories within D:\inetpub\sites.
I've looked through the docs and found examples only using DB queries. I am using <cfdirectory> to get a list of directories.
<cfdirectory action="list"
directory="#expandPath("../../")#"
name="webDirectories">
<cfquery name="getInfo" dbtype="query">
select sum(size) as total, name
from webDirectories
group by name
</cfquery>
<h1>Web Server Disk Usage Analysis</h1>
<!--- Bar graph, from Query of Queries --->
<cfchart format="flash"
xaxistitle="Client"
yaxistitle="Disk Usage">
<cfchartseries type="bar"
query="getInfo"
itemcolumn="name"
valuecolumn="size">
<cfoutput query="getInfo">
<cfchartdata item="#name#" value=#Round(total/1000)*1000#>
</cfoutput>
</cfchartseries>
</cfchart>
I would like to have the clients listed in the x-axis and usage on the y-axis. How can I achieve this?

Your chart code is wrong. I changed it to this, and it worked for me:
<h1>Web Server Disk Usage Analysis</h1>
<!--- Bar graph, from Query of Queries --->
<cfchart format="flash"
xaxistitle="Client"
yaxistitle="Disk Usage">
<cfchartseries type="bar"
query="getInfo"
itemcolumn="name"
valuecolumn="total" />
</cfchart>
If you want to do your round(total/100)*1000, you can just massage the query further before feeding it into the chart.

Related

Why is cfoutput being ignored?

I have a very simple CFML page as follows:
<cfquery name="qry" datasource="#application.db.source#" username="#application.db.user#" password="#application.db.pass#">
SELECT * FROM changemgmt.rfc WHERE rfc_id = <cfqueryparam cfsqltype="CF_SQL_INTEGER" value="0">;
</cfquery>
<cfoutput query="qry">
#qry.RecordCount#
</cfoutput>
My <cfoutput> tag is not working as I would expect. If you were to look at the source code of this page, it would be entirely composed of empty lines. It's as if the <cfoutput> tag is being parsed out by the server. However if I change the code to:
<cfoutput>
#qry.RecordCount#
</cfoutput>
I am using Lucee as my backend CFML engine. Can anyone explain to my why there is a difference?
<cfoutput query="qry"> this is used to loop throw all the rows in the query. If your query result have no rows, the execution will never reach the login with in the <cfoutput query="qry">. But if there are 1+n rows in the result, your code will print the recordcount 1+n times.
In this case if all you want is to print recordcount of the result, then you just need to use <cfoutput>#qry#</cfoutput>
But if you want to print values each row of the query then you can use <cfoutput query="qry">
<cfoutput query="qry">
<div>
<span>#qry.rfc_id#</span>
<span>#qry.name#</span>
...
</div>
</cfoutput>

Uploading the file names of my images to my database table

I'm having an issue with uploading or looping through the the file names of my images to my database table.
I am able to select various images and upload the selected image on my local machine to a specific folder that I designate. After the image files are put into my folder, I am having some difficulties because I want to insert the file names of the images that I just inserted into my folder, into my database. I'm trying to use the cffile parameters to do that.
My question: Being that it is multiple files being uploaded at once, do I need to do a cfloop on a cfquery insert in order to capture and insert the names into my database? My attempt at the code is below. The upload workd just fine, but it chokes out at the insert portion. What do you think could be the issue?
<cfparam name="form.fileUpload3" default="">
<cfif len(trim(form.fileUpload3))>
<cffile action="uploadall"
fileField="fileUpload3"
destination="#cookie.c.webpathmultipleimages#"
accept = "image/jpeg, image/png, image/jpeg"
nameconflict="makeunique">
<!---This is where i'm running into my issue--->
<cfloop INDEX="i" LIST="#Form.fileUpload3#">
<cfquery name="addtoimage">
insert into image (imaid, imacomid, imaname)
Value (
'00',
'#cookie.communityID#',
'#file.clientfile#'
)
</cfquery>
</cfif>
The cffile returns an array, but you used a list loop. So, you got the error. Try it with an array loop.
<cfif len( form.image )>
<cffile action="uploadall" filefield="image"
destination="#ExpandPath('.\uploadImages\')#"
result="fileName"
nameconflict="makeunique">
<cfloop array="#fileName#" index="image">
<cfquery name="imageUpload" datasource="uploadMultipleImage">
insert into uploadImage (imageName)
values
(
<cfqueryparam value="#image.serverfile#" cfsqltype="cf_sql_varchar">
)
</cfquery>
</cfloop>
</cfif>

Conditional CF Record Count

I'm trying to save my database server a few requests by querying a large number of items from several categories all at once, then using <cfif ... > statements to filter those results into unique tables I'm showing for each category. I'm looking to find record counts for each of the categories returned, not just the record count of the overall query.
The basic code is:
<cfinvoke component="..." method="..." returnvariable="session.queryList">
...
</cfinvoke>
<cfoutput #session.queryList#>
<cfif #category# eq "A">
[Table for A things]
</cfif>
<cfif #category# eq "B">
[Table for B things]
</cfif>
<cfif #category# eq "C">
[Table for C things]
</cfif>
</cfoutput>
I don't want to use "ORDER BY category" here because the tables are actually on different divs we're hiding and showing, so we need separate tables.
The problem I'm running into is that I want the "Table for A Things" to say "No results" if there is no records returned where category="A", but RecordCount seems to apply to the entire query. Is there any way to say something along the lines of <cfif #queryList.RecordCount# WHERE #category# eq "A" GT "0">?
QoQ can help.
<cfinvoke component="..." method="..." returnvariable="session.queryList">
...
</cfinvoke>
<!---then run QoQ on it--->
<cfquery name="catA" dbtype="query">
select * from session.queryList where category ="A"
</query>
<cfquery name="catB" dbtype="query">
select * from session.queryList where category ="B"
</query>
<cfif catA.recordcount>
<cfoutput query="catA">
[Table for A things]
</cfoutput>
<cfelse>
No Records for A things
</cfif>
<cfif catB.recordcount>
<cfoutput query="catB">
[Table for B things]
</cfoutput>
<cfelse>
No Records for B things
</cfif>
I believe you are trying to do the following. <cfoutput> has a feature that helps you group the query results given the query is ordered by the grouping item.
<cfoutput query="#session.queryList#" group="category">
<h3>Category #category#</h3>
<table>
<tr><th>...</th><th>...</th></tr>
<cfoutput><!--- This cfoutput loops through the each record in the group. --->
---rows---
</cfoutput>
<table>
</cfoutput>
QofQ is slow. You can accomplish this with a single round trip to mySQL:
SELECT someColumn, category, count(*) AS categoryCount
FROM theTable
GROUP BY category
ORDER BY category, someColumn
Grouping will give you a count per category which you can use in CFML.
<cfoutput query="session.queryList" group="category">
<cfif categoryCount eq 0>
No Records for #category#. =(
</cfif>
<cfoutput>
#someColumn#<br>
</cfoutput>
</cfoutput>

Using client-side gauge chart

I am trying to build a client-side gauge chart in CF10. I would like to customize the high and low end of the gauge. But the scaleTo value has no effect. The highest number is always the highest data value. Is there a way to customize the highest number on the gauge?
Here is my cf code:
<cfchart format="html" scalefrom="0" scaleto="40">
<cfchartseries type="gauge">
<cfchartdata item="Series1" value="15">
<cfchartdata item="Series2" value="10">
</cfchartseries>
</cfchart>
And here is the output shown in the browser.

cffeed function: show just most recent post?

We have a function to pull RSS feeds and display the post on a ColdFusion page using this code:
<cfset rssUrl = "rss1">
<cffeed action="read" source="#rssUrl#" query="fitness" properties="info">
<cfset rssUrl2 = "rss2">
<cffeed action="read" source="#rssUrl2#" query="nutrition" properties="info">
<cfif #fitness.PUBLISHEDDATE# gt #nutrition.PUBLISHEDDATE#>
<cfset entries="fitness">
<cfelse>
<cfset entries="nutrition">
</cfif>
Output done via:
<cfoutput query="#entries#">
Problem is, the RSS feed has several posts and we only want to show one. Any thoughts on how to get it to pull and display only the most recent post? (We want the feed to have multiple posts, so right now our non ideal solution is to set maximum posts per feed to 1)
cfoutput/query=".." will go over an entire query. If you only want to do the first row, use:
<cfoutput>
Title from row 1: #somequery.title[1]#
</cfoutput>
Basically - array notation on the column. Make sense?
There's nothing wrong with Ray's answer, but here are some other options.
<cfoutput query="#entries#" maxrows="1">
Offers the least disruption to your existing code and, should you decide to change the number of rows displayed (like, via a user setting) it's an easy change.
OR
If you copy the query object rather than the query name (which isn't actually a copy but a copy by reference)
<cfset entries = fitness>
instead of
<cfset entries = "fitness">
you can do this
<cfoutput>
#entries.columnName1#
#entries.columnName2#
<!--- etc. --->
</cfoutput>
which will, by default, display only the first row of the query.