[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 174
  • Last Modified:

Query and Loop, need to display 8 images with 2 defined sizes, loop is displaying wrong sequence

I have a main page with several templates.  i defined the classes in my css page and then on this main page, the images are displayed according to the template.  all templates work fine except the one that displays 8 images, layout 7,  in 2 groups of 4 images.  

in my database, the images are inserted with the following sizes:
90 * 100  or 120 * 100

This template has the following format:

Text TextmText Text Text Text
Text TextmText Text Text Text

image 1 image 2 image 3 image 4
image 5 image 6 image 7 image 8

2 of the images in the first group and 2nd group should be 90 * 100, while the other images in both groups are 120 * 100.

so it should be:
90 * 100  90 * 100  120 * 100  120 * 100
90 * 100  90 * 100  120 * 100  120 * 100

regardless of the order they were entered into the database.

the template is displaying the images, but not in the correct sequence, instead of getting the above, I am getting all four images that are 90px wide  at the top and all 4 images that 120px wide at the bottom and this is wrong.

I tried a loop with startrow and endrow, but this only pulled the records according to how they are in the database.  I also had a loop with  a cfset for the sizes and that did not work.

Here's part of the code of my template.  How can i get the images to be displayed properly?  

========test1.cfm (layout page)================================

<cfquery name="newContent" datasource="#request.dsn#">
select * FROM PContent
LEFT JOIN PContentParts
ON PContent.ContentID=PContentParts.ContentID
LEFT JOIN PImages
ON PContentParts.ImageID=PImages.ImageID
WHERE PContent.ContentID=<cfqueryparam cfsqltype="cf_sql_integer" value="#URL.CYCLE#">
</cfquery>

<cfoutput query="newContent" group="body">
<cfswitch expression="#template#">

other case values here....and templates...

problem template...
<cfcase value="7"><!--- Title, Text, and 2 rows of images, 4 in each row --->
<div id="container">
<span class="head">#title#</span><br><br>      
#body#      
  <div id="image-group">  
       <cfloop query="newContent" startrow="1" endrow="4">
  <cfif width IS 90>  
        <img alt="#alt#" class="w" src="/images/#image#" width="#width#" height="#height#"/>
       <cfelse>
        <img alt="#alt#" class="x" src="/images/#image#" width="#width#" height="#height#"/>
        </cfif>
       </cfloop>      
       </div>

<!--- begin row 2 --->
  <div id="image-groupB">  
       <cfloop query="newContent" startrow="5" endrow="8">
  <cfif width IS 90>  
        <img alt="#alt#" class="w" src="/images/#image#" width="#width#" height="#height#"/>
       <cfelse>
        <img alt="#alt#" class="x" src="/images/#image#" width="#width#" height="#height#"/>
        </cfif>
       </cfloop>      
       </div>

</div>
</cfoutput>

Thanks in advance for your patience and help.

0
synergeticsoul
Asked:
synergeticsoul
1 Solution
 
aseusaincCommented:
Maybe you should add a column to your database for "display order", the in your SQL query add "ORDER BY displayorder"  This way, regardless of the order you have things entered into the db, you will be able to control the order in which they are displayed.
0
 
synergeticsoulAuthor Commented:
Duh...that is a good idea. I feel silly. Thank You.  
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now