Delete output once recordcount hits zero? - coldfusion

I'm trying to figure out how I can delete/get rid of this output if RECORDCOUNT=0. I don't want to
show the output if RecordCount=0. Maybe there can be a better way to show this using a form? But this works.
I have been looking online for any help but I can't find something that can help me.
<cfquery datasource ="Intranet" name="GetDeptSubmissions">SELECT * FROM CSEReduxResponses</cfquery>
<cfquery dbtype="query" name="GetPending">SELECT * FROM GetDeptSubmissions WHERE status = 1 AND execoffice_status = 0</cfquery>
<cfquery dbtype="query" name="GetApproved">SELECT * FROM GetDeptSubmissions WHERE status = 1 AND execoffice_status = 1</cfquery>
<cfquery dbtype="query" name="GetDenied">SELECT * FROM GetDeptSubmissions WHERE status = 1 AND execoffice_status = 2</cfquery>
<cfoutput>
<h2>Comments / Ratings Administration</h2>
<div>
<div class="display_count pending_outer">
<div class="display_count_desc pending_inner">Pending</div>
<cfif GetPending.RecordCount gt 0><a href="cse_execoffice_pending.cfm"></cfif>
<span class="display_count_number">#GetPending.RecordCount#</span>
<cfif GetPending.RecordCount gt 0></a></cfif>
</div><!--- /div class="display_count" --->
..........................
</div>
</cfoutput>

Put the record count check around the whole div / output depending on how much you need to show.
<cfif GetPending.RecordCount gt 0>
<div class="display_count pending_outer">
<div class="display_count_desc pending_inner">Pending</div>
<span class="display_count_number">
#GetPending.RecordCount#
</span>
</div>
</cfif>

Related

trying to get categories name along with the images in dynamic table rows

Habing this code for coldfusion but after trying couple of times, i am always ending up showing categories multiple times and images multiple times too, i tried using the group attribute but that it also not doing its work, not sure what is going wrong
here is my complete code
<cfparam name="url.mode" default="">
<cfquery name="ImagesCategories">
select * from rivereast_gallerycategories
</cfquery>
<div id="spacingorder" align="right"><cfoutput>#DateFormat(now(),'long')#</cfoutput></div>
<div class="row">
<div class="col-xs-12 col-sm-12">
<h2>View Gallery Contents</h2>
<div align="right"> </div>
<div align="center">
<cfset variables.newrow = False>
<table align="center" width="100%" cellpadding="1" cellspacing="5" class="borderspacing">
<tr>
<cfif ImagesCategories.recordcount>
<cfoutput query="ImagesCategories">
#gallerycategory#
<cfquery name="filesListings">
select c.galleryCatID,c.ImageID,c.ImageName as name,c.updatedon
from rivereast_gallery c
order by updatedon desc
</cfquery>
<cfloop query="filesListings">
<cfif variables.newrow EQ true>
<tr>
</cfif>
<td height="30" valign="middle">
<div id="previewArea">
<cfset filename = Listlast(filesListings.name,'~')>
<img src="#request.weburl#uploads/#filename#" class="img-fluid"><br>
<input type="checkbox" class="ImagesDelete" name="delItems" data-id="#filesListings.imageID#"> Delete #filesListings.currentRow#
</div>
</td>
<cfif filesListings.currentRow MOD 5 EQ 0>
</tr>
<cfset variables.newrow = true>
<cfelse>
<cfset variables.newrow = false>
</cfif>
</cfloop>
</cfoutput>
<cfelse>
<td colspan="3" align="center"><h2>No Files Found</h2></td>
</cfif>
</tr>
</table>
<cfif filesListings.recordcount>
<div><input type="button" name="deleImages" id="delImages" class="button btn btn-info" value="Delete"></div>
</cfif>
</div>
</div>
</div>
what went wrong here
Hard to say without seeing the data, but it might be this. You are running this query inside a query loop.
<cfquery name="filesListings">
select c.galleryCatID,c.ImageID,c.ImageName as name,c.updatedon
from rivereast_gallery c
order by updatedon desc
</cfquery>
Note that it has no where clause. That could be the reason for seeing the same data more than once.
Assuming your database is somewhat normalized, the recommended fix is to just have one query that gets data from both tables at once. The sql would look something like this.
select JustTheFieldsYouNeed
from rivereast_gallerycategories c join rivereast_gallery g
on c.categoryID = g.categoryID
where some condition is met
I'd join the two queries
SELECT c.*, g.galleryCatID, g.ImageID, g.ImageName as name, g.updatedon
FROM rivereast_gallerycategories c, rivereast_gallery g
WHERE c.galleryCatID = g.galleryCatID
ORDER BY c.gallerycategory, g.ImageName
and then use
<cfoutput query="ImagesCategoriesAndFiles" group="category">
Cleaner code, less confusion.
See example here of how to use cfoutput for grouping record output: https://cfdocs.org/cfoutput

Display Events in Fullcalendar underneath calendar?

I am having a hard time to do this. The calendar Displays the events in the calendar however, I would like to be able to list the events as well below the calendar so you can see the full name of the events that are in the current month. I have the following code(I am using coldfusion and Mura and I am new to both):
<cffunction name="MultipleFeaturedEvents">
<cfargument name="feedName" type="string" default="702771E7-155D-0201-11DF8865B175735F"/>
<cfargument name="maxMonths" type="numeric" default="3" />
<cfargument name="groupDailyEvents" default="true" />
<cfscript>
var rs = '';
var subRS1 = '';
var local = {};
local.listIDs = '';
local.util = $.getCalendarUtility();
local.rsItems = local.util.getCalendarItems(calendarid=arguments.feedName, start=Now(), end=DateAdd('m', val(4), Now()));
var qoq = new Query();
qoq.setDBType('query');
qoq.setAttributes(rs=local.rsItems, maxRows=val(1));
qoq.setSQL('
SELECT *
FROM rs
ORDER BY displaystart ASC
');
var qoqResult = qoq.execute().getResult();
local.it = $.getBean('contentIterator').setQuery(qoqResult);
</cfscript>
<cfsavecontent variable="local.str">
<cfoutput>
<cfset ctr=1 />
<!---<div>#local.it.hasNext()#</div>--->
<cfloop condition="(local.it.hasNext()) AND (ctr LT 4)">
<cfset local.item = local.it.next() >
<cfif not ListFind(local.listIDs, local.item.getValue('contentid'))>
<cfif ctr eq 1>
<!--- TODO: set a default image if no image is available --->
<div class="hidden-xs col-md-2">
<p class="upcoming-events-image"><img src="#local.item.getImageURL()#" alt="#HTMLEditFormat(local.item.getTitle())#"> </p>
</div>
<div class="col-md-offset-0 col-md-4" id="featured-event">
<h3>#HTMLEditFormat(local.item.getMenuTitle())#</h3>
<i class="fa fa-calendar fixIconCal"></i>
<!---#local.item.getDisplaystart()#--->
#LSDateFormat(local.item.getValue('displayStart'), "mmm d, yyyy")#
<cfquery dbtype="query" name="subRS1">
select *
from rsItems
where rsItems.contentid = <cfqueryparam value="#local.item.getValue('contentid')#" />
</cfquery>
<cfif subRS1.recordcount gt 1>
<!--- end date --->
<cfset enddate = ListLast(ValueList(subRS1.displaystop)) />
<cfif IsValid('date', enddate)>
- #LSDateFormat(enddate)#
</cfif>
</cfif>
<br />
<i class="fa fa-clock-o"></i>
#timeFormat(local.item.getValue('displayStart'), "h:mm tt")# - #timeFormat(local.item.getValue('displayStop'), "h:mm tt")#
<br />
<i class="fa fa-map-marker"></i>
Location Information
<!--- Summary --->
<div class="featured-event-summary">
<cfif Len(local.item.getValue('summary'))>
#local.item.getValue('summary')#
</cfif>
</div>
</div>
<cfelse>
</cfif>
</cfif>
</cfloop>
</cfoutput>
</cfsavecontent>
<cfreturn local.str />
</cffunction>
Below is what I am trying to do:
Any help would be appreciated. Thanks
Don't know if you can use plain JS (I don't know ColdFusion), but typically you can retrieve all FullCalendar events by invoking:
$('#calendar').fullCalendar('clientEvents')
Which returns array of Events, then you can iterate over it and render some list.
Hope this helps.
EDIT:
So maybe something like
$('#calendar').fullCalendar('clientEvents', function(ev) {
//will loop for each event you have in the calendar
console.log(ev); //event
});
And you can use something like:
$('#calendar').fullCalendar('clientEvents', function(ev) {
$('.your-list-container').append('<div>' + ev.title + '</div>');
});
this is js code , hope its help you ..
//get the start and the end of the current view
var startDate = $('#idOfCalendar').fullCalendar('getView').start;
var endDate = $('#idOfCalendar').fullCalendar('getView').end;
var eventsNames= new Array();
var todaysEvents = $('#idOfCalendar').fullCalendar('clientEvents', function (event) {
if (event.start >= startDate && event.start <= endDate
|| event.end >= startDate && event.end <= endDate) {
eventsNames.push(event.title)
//take what do you whant from the event object
return true;
}
});

ColdFusion Options removed after selecting option

I'm having trouble with my ColdFusion code. I'm trying to create a simple HTML select form using cfloop to populate the options. it works, and when you select an option, it pulls that option from the db. but once you do that, the only option available is the option previously selected. What am I doing wrong?
<!--- Query the DataBase --->
<cfparam name="url.colors" default="">
<cfif structKeyExists(form, "colordb")>
<cfset url.colordb = form.colordb>
</cfif>
<cfquery datasource="bentest" name="colors">
SELECT *
FROM color_codes
<cfif structKeyExists(url,"colordb") and isNumeric(url.colordb)>
WHERE id=#url.colordb#
</cfif>
</cfquery>
<!--- Add Selector for user to select a color --->
<div class="selector">
<cfoutput>
<form action="?contentId=colorPickdb" name="clr" method="post" class="clr">
<select class="clr" name="colordb" onChange="submit();">
<option selected>Select A Color!</option>
<cfloop query="colors">
<option value="#colors.id#">#colors.color#</option>
</cfloop>
</select>
</form>
</cfoutput>
</div>
<div class="dump">
<!--- Output results of Query --->
<p><cfif structKeyExists(form, "colordb")>
<cfoutput query="colors">
#colors.color# <br>
#colors.hexvalue# <br><br>
</cfoutput>
</cfif>
<br>
</p>
</div>
You can use query of query here.
<!--- Query the DataBase --->
<cfparam name="url.colors" default="">
<cfquery datasource="bentest" name="colors">
SELECT *
FROM color_codes
</cfquery>
<!--- Add Selector for user to select a color --->
<div class="selector">
<cfoutput>
<form action="?contentId=colorPickdb" name="clr" method="post" class="clr">
<select class="clr" name="colordb" onChange="submit();">
<option selected>Select A Color!</option>
<cfloop query="colors">
<option value="#colors.id#">#colors.color#</option>
</cfloop>
</select>
</form>
</cfoutput>
</div>
<div class="dump">
<!--- Output results of Query --->
<p>
<cfif structKeyExists(form, "colordb")>
<cfquery dbtype="query" name="colorSelected">
SELECT *
FROM colors
WHERE id=#form.colordb#
</cfquery>
<cfoutput query="colorSelected">
#colorSelected.color# <br>
#colorSelected.hexvalue# <br><br>
</cfoutput>
</cfif>
<br>
</p>
</div>

fixing display of items in 2 columns layout dynamically

I got the code, it displays items one after another:
<ul class="side-products-list padleft">
<!-- Designers #1 Starts -->
<cfoutput query="lstdesigners">
<cfset getProducts = Application.tools.getDesignerProducts(cw_designerID)>
<li class="clearfix">
<h5>#reReplace(lcase(cw_designerName),"(^[a-z])","\U\1","ALL")# (#getProducts.total#)</h5>
<cfif FileExists(Expandpath('corecontrol/designers/#image#'))>
<img src="corecontrol/designers/#image#" alt="#cw_designerName#" class="img-responsive" />
<cfelse>
<img src="#request.imagespath#nomovieimage.jpg" alt="#cw_designerName#" class="img-responsive" />
</cfif>
</li>
</cfoutput>
<li>
<h5>All Designers</h5>
<cfoutput><img src="#request.imagespath#icons-design.gif" width="122" height="114" alt="All Designers" class="img-responsive" /></cfoutput> </li>
<!-- Designers #1 Ends -->
</ul>
I want to show two column layout for this stuff, i am bit lost in this
any idea how can i use the mod operand with this ul li
Does'nt look like much of an attempt Ramesh but I'll assume you are at the beginning and need rudimentary help here. The following is Un-debugged code (though Scott will probably notice if I add an eggregious error. :)
<cfset breakpoint = int(lstdesigners.recordcount / 2)>
<div id="thisiscolumn1">
<cfloop query="lstdesigners">
<cfif currentrow le breakpoint>
... do stuff for column 1 - your li code prob. goes here.
</cfif>
</cfloop>
</div>
<div id="thisiscolumn2">
<cfloop query="lstDesigners">
<cfif currentrow gt breakpoint>
.... do stuff for column 2 .. li code.. etc.
</cfif>
</cfloop>
</div>
This code is not optimal (it loops through the query twice and gives you the first half then the next half). Alternately you could use the "startrow / Maxrow" attributes of cfoutput or cfloop to acheive the same looping result.
Again this is just psuedo-code - an approach that will work. But the legwork will have to be up to you.

Coldfusion Looping over query

I have a query result something like
ID IDParent Name Title
--------------------------------------
1 -1 Test1 Test1_Title
2 -1 Test2 Test2_Title
3 -1 Test3 Test3_Title
4 2 SubTest2 SubTest2_Title
5 2 SubTest3 SubTest3_Title
6 2 SubTest4 SubTest4_Title
7 3 SubTest6 SubTest8_Title
8 3 SubTest8 SubTest10_Title
with menu and submenu options.I want to loop over the menu option where IDParent is -1 and after each menu Item where IDParent -1 I would like to loop its child items.
Does coldfusion provides such grouping when looping over queries?
Thanks
CFOUTPUT supports query groupings as well.
<cfquery name="qGetTests" datasource="#DSN#">
SELECT ID, IDParent, Name, Title
FROM Menu
ORDER BY IDParent, Name
</cfquery>
<cfoutput query="qGetTests" group="IDParent">
#IDParent#<br />
<cfoutput>
#ID# #Name# #Title#<br />
</cfoutput>
</cfoutput>
That's pretty easy with Query of Queries (QoQ) and a little recursion:
<!-- database query, sorted in the way you want to display the results -->
<cfquery name="Menu" datasource="#YourDSN#">
SELECT ID, IDParent, Name, Title
FROM Menu
ORDER BY Name
</cfquery>
<!-- output menu -->
<cfset OutputQueryRecursive(Menu, -1)>
<!-- support function -->
<cffunction name="OutputQueryRecursive">
<cfargument name="BaseQuery" type="query" required="yes">
<cfargument name="ParentId" type="numeric" required="yes">
<cfquery name="CurrLevel" dbtype="query">
SELECT * FROM BaseQuery WHERE IDParent = #ParentId#
</cfquery>
<cfif CurrLevel.RecordCount gt 0>
<ul>
<cfoutput query="CurrLevel">
<li id="menu_#ID#">
<span title="#HTMLEditFormat(Title)#">#HTMLEditFormat(Name)#</span>
<cfset OutputQueryRecursive(BaseQuery, ID)>
</li>
</cfouptut>
</ul>
</cfif>
</cffunction>
If you have any control of the SQL generating that query result, you could consider getting the DB to get you the data back in the right format in the first place. Approaches for Oracle and SQL server are covered here and there's some options for mySQL here
If your menu data is always going to be small, then there'll be no problem with Tomalak's solution, but if you're ever going to have large numbers of menu items then I'd test that it still performs ok.
consider qTestQuery contains the values
<cfset qTestQuery1 = qTestQuery>
<cfloop query="qTestQuery">
<cfif qTestQuery.IDParent eq -1>
<span class="main-menu">#qTestQuery.name#</span>
</cfif>
<cfset local.parentId = qTestQuery.IDParent>
<cfloop query="qTestQuery1">
<cfif qTestQuery1.IDParent eq local.parentId>
<span class="sub-menu">#qTestQuery1.name#</span>
</cfif>
</cfloop>
</cfloop>