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

Posted on 2006-05-13
Last Modified: 2013-12-24
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
ON PContentParts.ImageID=PImages.ImageID
WHERE PContent.ContentID=<cfqueryparam cfsqltype="cf_sql_integer" value="#URL.CYCLE#">

<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>      
  <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#"/>
        <img alt="#alt#" class="x" src="/images/#image#" width="#width#" height="#height#"/>

<!--- 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#"/>
        <img alt="#alt#" class="x" src="/images/#image#" width="#width#" height="#height#"/>


Thanks in advance for your patience and help.

Question by:synergeticsoul
    LVL 7

    Accepted Solution

    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.

    Author Comment

    Duh...that is a good idea. I feel silly. Thank You.  

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Scale it in WD Gold

    With up to ten times the workload capacity of desktop drives, WD Gold hard drives employ advanced technology to deliver among the best in reliability, capacity, power efficiency and performance.

    This is a guide to setting up a new WHM/cPanel Server to be used for web hosting accounts. It is intended for web hosting company administrators and dedicated server owners. For under $99 per month (considering normal rate of Big Data Cetnters like …
    Periodically we have to update or add SSL certificates for customers. Depending upon your hosting plan you may be responsible for the installation and/or key generation. In the wake of Heartbleed many sites were forced to re-key. We will concen…
    Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
    Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    12 Experts available now in Live!

    Get 1:1 Help Now