I am trying to display 2 images, and skip one if it matches the following criteria (<cfif myDir.name eq property_mainimage> which works fine, and then continue onto the next image and display the next image until I have a total of 2 images. But when the criteria image is say in row 5, the loop displays 3 images, when the criteria image is say row 1, it displays 2 images.
There doesn't seem to be a skip row in cfloop?
I have tried <cfif counter gt 3 > <cfabort> which works but it displays the 3 images still of the criteria image is in a row greater than 3. Below is what i'm working with...
<cfdirectory directory="C:\Domains\domain.com\wwwroot\uploads\images\#property_ID#\" filter="*.jpg" name="myDir" type="file" sort="datelastmodified">
<ul>
<cfset counter = 0>
<cfset endrowvalue = 3 >
<cfloop query="myDir" endRow="#endrowvalue#">
<cfset counter = counter +1 >
<li>
<cfif right(myDir.name,4) is ".jpg">
<cfif fileexists("C:\Domains\ domain.com\wwwroot\uploads\ images\#property_ID#\#left(mydir.name,len(myDir.name)-4)#.jpg")>
<cfif myDir.name eq property_mainimage>
DO NOT SHOW THIS IMAGE
<cfelse>
<cfset endrowvalue = 1 >
<cfset myDir.endRow = 1 >
test #endrowvalue#
test #counter# <img src="#request.root#uploads/images/#property_ID#/#myDir.name#" border="0" width="230px" style="margin-bottom:15px;" />
</cfif>
</cfif>
</cfif>
</li>
</cfloop>
</ul>
any help would be most appreciated.
I would use a counter to count when you show the image. Once you get to 2 images displayed break out of the loop.
<cfdirectory directory="C:\Domains\domain.com\wwwroot\uploads\images\#property_ID#\" filter="*.jpg" name="myDir" type="file" sort="datelastmodified">
<ul>
<cfset counter = 1>
<cfloop query="myDir">
<li>
<cfif right(myDir.name,4) is ".jpg">
<cfif fileexists("C:\Domains\ domain.com\wwwroot\uploads\ images\#property_ID#\#left(mydir.name,len(myDir.name)-4)#.jpg")>
<cfif myDir.name eq property_mainimage>
DO NOT SHOW THIS IMAGE
<cfelse>
<!--- image displayed increment coutner --->
<cfset counter++>
<img src="#request.root#uploads/images/#property_ID#/#myDir.name#" border="0" width="230px" style="margin-bottom:15px;" />
</cfif>
</cfif>
</cfif>
<cfif counter EQ 2>
<cfbreak>
</cfif>
</li>
</cfloop>
</ul>
This is a formatted comment. Your code has this:
<cfset endrowvalue = 3 >
<cfloop query="myDir" endRow="#endrowvalue#">
<cfif myDir.name eq property_mainimage>
DO NOT SHOW THIS IMAGE
<cfelse>
<cfset endrowvalue = 1 >
You would have to test it to be sure, but I suspect that the endRow attribute of your cfloop tag will continue to be 3, even if you change the value of the endrowvalue variable to 1.
This might not be the cause of your current problem, but, it my suspicians are correct, you will either have a problem elsewhere or you are running a pointless command.
Related
I have the following type of structure
https://prnt.sc/wkerdv
in the above only the first one has childrens but the possibility is childrens can have childrens and so on, but i prefer to display only 3 levels deep as horizontal menu
i am struk the loop where i had to add the loop properly to create the menu bar, i am trying to create menu like this
https://prnt.sc/wket5s
so here is what i am trying
<cfoutput>
<ul>
<cfloop from="1" to="#arrayLen(data.item)#" index="i">
<cfset x = data.item[i]>
<cfloop collection="#x#" item="key">
<cfif Structkeyexists(key,'Item')>
<cfloop from="1" to="#arrayLen(data.item)#" index="i">
<cfset x = data.item[i]>
<cfelse>
</cfif>
<cfdump var="#key#">
<!--- <cfloop from="1" to="#arrayLen(key.item)#" index="d">
<cfset n = key.item[d]>
<!--- <li>#d#:#n[d]#</li> --->
<cfdump var="#n#">
</cfloop>
<li>#key#:#x[key]#</li>--->
</cfloop>
</cfloop>
</ul>
</cfoutput>
the html code behind the above second screen is like this
<ul class="menu-list">
<cfloop from="1" to="#ArrayLen(data.menu.item)#" index="toplevel">
<li>#toplevel#
</cfloop>
<li class="active">HOME
<ul class="menu-dropdown">
<li>Home One</li>
<li>Home Two</li>
<li>Home Three
<ul class="thirdlevel-menu">
<li>Thirdlevel</li>
<li>Thirdlevel</li>
<li>Thirdlevel</li>
</ul>
</li>
</ul>
</li>
<li>ABOUT</li>
<li>SHOP
I would like to run one query + output and in case no records exist run second query + output and in case both have no records then redirected to
<test1.RecordCount eq 0>
but the problem is that I can only use one <cfelse>
Any idea?
The Code for one query + output and RecordCount
<cfif test1.RecordCount eq 0>
<!--- Display some message.--->
<cfelse>
<cfoutput query="test1">
<!--- Display some other message --->
</cfoutput>
</cfif>
If I understand your question correctly, you should be able to use nested <cfif ...> conditions.
Something like:
<cfif test1.RecordCount gt 0>
<cfoutput query="test1">
<!--- Display test1 query results --->
</cfoutput>
<cfelse>
<cfif test2.RecordCount gt 0>
<cfoutput query="test2">
<!--- Display test2 query results --->
</cfoutput>
<cfelse>
<!--- Display some message.--->
</cfif>
</cfif>
Or you could use <cfelseif> like this:
<cfif test1.RecordCount gt 0>
<cfoutput query="test1">
<!--- Display test1 query results --->
</cfoutput>
<cfelseif test2.RecordCount gt 0>
<cfoutput query="test2">
<!--- Display test2 query results --->
</cfoutput>
<cfelse>
<!--- Display some message.--->
</cfif>
<cfif dir.name IS NOT "Thumbs.db">
This code excludes Thumbs.db from being called in the cfoutput query, but what if I want another file excluded? Not sure how to exclude more than one item though.
Right now have
<cfset counter = 1 />
<cfoutput query="dir1">
<cfif !listfindNoCase( 'Thumbs.db,2. Electric Accounts Tracking Report.xls,1. Electric Accounts Performance Analytics.xls', dir1.name) >
<a href="/091_AU20100226/020_Cost_Analyses/010_Electric/Flatten_Files/#dir1.name#" target="_blank">
#dir1.name#</a><br />
<cfset counter++ /> </cfif> </cfoutput>
You can use listFind() or listFindNoCase().
<cfif !listfindNoCase( 'Thumbs.db,otherFile.txt', dir.name) >
...do stuff...
</cfif>
I am trying to compare images and find if they are same or not. Images can have same name but the actual image might be different. The code that I have so far.
<cfset dirToReadFrom = #ExpandPath( '../properties-feed/unzipped/' )# />
<cfdirectory
action="list"
directory="#dirToReadFrom#"
listinfo="name"
name="qFile"
sort="asc"
filter="*.jpg"
/>
<cfset images = ArrayNew(1)>
<cfoutput query="qFile">
<cfset ArrayAppend(images, #qFile.name#)>
</cfoutput>
<cfset dirToCreate = #ExpandPath( './assets/images/resized/original/' )# />
<cfif not DirectoryExists(dirToCreate)>
<cfdirectory action = "create" directory = "#dirToCreate#" />
<cfoutput><p>Your directory has been created.</p></cfoutput>
</cfif>
<cfzip
action="unzip"
file="#ExpandPath( '../properties-feed/data.zip/' )#"
destination="#ExpandPath( './assets/images/resized/original/' )#"
overwrite="true"
/>
<cfset dirToReadFromOriginal = #ExpandPath( './assets/images/resized/original/' )# />
<cfdirectory
action="list"
directory="#dirToReadFromOriginal#"
listinfo="name"
name="qFileOriginal"
sort="asc"
filter="*.jpg"
/>
<cfset imagesLatest = ArrayNew(1)>
<cfoutput query="qFileOriginal">
<cfset ArrayAppend(imagesLatest, #qFileOriginal.name#)>
</cfoutput>
<!--- Loop over your current images --->
<cfloop query="qFileOriginal">
<!--- Check for a matching file name --->
<cfquery name="fileExists" dbtype="query">
SELECT
COUNT(*) AS num_Rec
FROM
qfile
WHERE
name = <cfqueryparam cfsqltype="cf_sql_varchar" value="#qFileOriginal.name#" />
</cfquery>
<!--- do we have a matching file name? --->
<cfif val(fileExists.num_rec)>
<cfimage action="read" name="newImage" source="#dirToReadFrom##qFile.name#"/>
<cfimage action="read" name="originalImage" source="#dirToReadFromOriginal##qFileOriginal.name#"/>
<cfset newImageBlob = ImageGetBlob(newImage) />
<cfset originalImageBlob = ImageGetBlob(originalImage) />
<!--- Compare --->
<cfif toString(newImageBlob) eq toString(originalImageBlob) >
Images are same
<cfelse>
DIFFERENT
</cfif>
</cfif>
</cfloop>
The code doesn't seem to be working. Can Anyone see what am I doing wrong?
Update 1 from comments
The result that I actually get is that the first images are same and the rest of images in files are different. But this is not correct as most of the images that I am comparing are same.
Update 2 from comments
It incorrectly identifies same images as being different. What I actually get is that the first two images are same and the rest is different. Which is not right as most of the images I have are same.
I've always just done this with BinaryEncode(), and then compare the resulting strings. You have to be careful though, as compression can make the files different even though they look (to the eye) exactly the same.
Hi am doing dynamic TR and TD in coldfusion, but apparently i am trying this kind of screen. here is my try with colfusion
<cfif variables.newrow EQ true>
<tr align="center">
</cfif>
<cfoutput query="gResults">
<cfquery datasource="#request.dsn#" name="nextqueries">
Query
</cfquery>
<td height="30" valign="middle"><strong>
<a href="viewdir.cfm?catID=#val(pic_id)#
<cfif isDefined('url.l') and url.l neq ''>&l=#url.l#</cfif>">
#pic_cat_name#</a></strong><br>
<cfloop query="nextqueries">
<cfquery datasource="#request.dsn#" name="showanother">
select * from
mytable as grlist
where pic_cid =
<cfqueryparam cfsqltype="cf_sql_numeric" value="#Trim(nextqueries.pic_id)">
</cfquery>
»
<a href="viewdir.cfm?catID=#val(pic_id)#
<cfif isDefined('url.l') and url.l neq ''>&l=#url.l#</cfif>">#pic_cat_name#
</a> </cfloop></td>
<cfif gResults.currentRow MOD 4 EQ 0>
</tr>
<cfset variables.newrow = true>
<cfelse>
<cfset variables.newrow = false>
</cfif>
</cfoutput>
trying to do like this:
http://screencast.com/t/oso4jkhBm3
There are a lot of potential improvements, but this answer will only deal with table rows. You start with:
<cfif variables.newrow EQ true>
<tr align="center">
</cfif>
Now I'm going to look for the closing tag. The only one I see is here:
<cfif gResults.currentRow MOD 4 EQ 0></tr></cfif>
and that line is inside a query loop. What this means is that you might have more than one closing tag, or you might not have any. You need exactly one. To solve this specific problem, you have to do this:
<cfif variables.newrow EQ true>
<tr align="center">
code to populate this table row
</cfif>
When you get that part sorted out, we can look at what goes into the details.
To get data to display in an html table from top to bottom then left to right like in the image linked in your question, you can do something similar to the following.
<!--- Get query results --->
<cfset arrayOFValues = arraynew(1)>
<cfset queryResults = querynew("Col1,Col2,Col3")>
<!--- Fill query with example data --->
<cfloop from="1" to="25" index="i">
<cfset queryaddrow(queryResults)>
<cfset querySetCell(queryResults, "Col1", "Col1 Row " & i)>
<cfset querySetCell(queryResults, "Col2", "Col1 Row " & i)>
<cfset querySetCell(queryResults, "Col3", "Col1 Row " & i)>
</cfloop>
<!--- Now have a query named queryResults with 25 rows --->
<!--- Set the number of columns and calculate the number of rows needed --->
<cfset numberOfColumns = 3>
<cfset rowsNeeded = ceiling(queryResults.recordcount / numberOfColumns)>
<cfoutput>
<table>
<cfloop from="1" to="#rowsNeeded#" index="curRow">
<tr>
<cfloop from="0" to="#numberOfColumns-1#" index="curCol">
<td>
#queryResults.Col1[(rowsNeeded * curCol) + curRow]#
</td>
</cfloop>
</tr>
</cfloop>
</table>
</cfoutput>
The first part is just creating a query result. I then find the number of rows that is needed to display the records by dividing the number of results returned in the query by the number of columns to be displayed. The ceiling is required for when the result is not a whole number.
We have to loop each column record with in the row to get the desired index. To find the required index of the field we have to take the row that’s being displayed + the column were on times the the number of rows that will be displayed.
If you know the number of columns you can hard code for them in the following manner and eliminate the inner loop.
<tr>
<td>#queryResults.Col1[3 * rowsNeeded]#</td>
<td>#queryResults.Col1[3 + 1*rowsNeeded]#</td>
<td>#queryResults.Col1[3 + 2*rowsNeeded]#</td>
</tr>