Efficiently Organizing Data Using Coldfusion Loops in Columns and Rows

My issue lies in pulling data from a database to display on my website. I have three keys/attributes (columns) - PostedDate, DataImage, and Source that need to be shown together in one div with the posted date at the top, image in the middle, and source at the bottom. While I have achieved this, I now need to loop over these 3 columns and create a new row after every set of 3 columns to avoid displaying them all as one big column or row.

The desired layout should look like this:

https://i.sstatic.net/7HJFg.jpg

However, whenever I try to refresh the webpage, it gives me a 404 or 500 error due to my current code:

        <!--- Set the number of columns you want to have --->
<cfset cols = 3> 
<cfset totalRows = ceiling(UIData.RecordCount / cols)>
<cfset output = 1>
<table width = "100%" border="0" align="center" cellpadding="2" cellspacing= "2">            
<cfloop from = "1" to = "#totalRows#" index = "thisRow">
<tr>
    <cfloop from = "1" to = "#cols#" index = "thisCol">

    <td width = "<cfoutput>#numberformat((100/cols), 99)#</cfoutput>%" align="center" nowrap style = "border: 1px solid #ccc;">

        <cfif output != UIData.recordCount>
            <cfoutput> 
            <div> <font style="font-size: .8em; line-height: .6em; padding-bottom: .8em;"><strong> #PostedDate# </strong></font> </div>
         <div> <img src="http://www.iowalum.com/uidata/images/#DataImage#" alt="" width="99%" height="264" style="padding-top:10px; padding-bottom:10px;" /> </div>
         <div id ="text"> #Source# </div> </cfoutput>
        <cfelse>
        <!--- Use <br> to display an empty cell --->
            <br>
        </cfif>
        <!--- Increment counter for the next record --->
        <cfset output = output + totalRows>
    </td>
    </cfloop>
    <!--- Set start position for the next row --->
    <cfset output = thisRow + 1>
</tr>
</cfloop>

Answer №1

This method could potentially offer a more straightforward solution.

<cfset ItemsPerRow = 3>     
<tr>
<cfoutput query="your query">
<td>#display something#    </td>
<cfif currentrow mod ItemsPerRow is 0>
</tr><tr>
<cfelseif currentrow equals recordcount>
</tr>
</cfif>
</cfoutput>
<tr>

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

What is the best way to display data not found in a table without needing to compare it with other tables in SQL?

Looking for a solution to match around 100 file names that come daily with the existing entries in the FILEINFO table. Is there a way to perform this check in one query? Appreciate any help! ...

Creating a dynamic website with user-friendly editing capabilities

Having a good understanding of html5 and css3, I am currently exploring ways to create a website that enables visitors to edit content in real time for all other users to see. While aware of the contenteditable attribute, I have found that it does not reta ...

Vue 3 feature: Click the button to dynamically insert a new row into the grid

Just starting out in the world of coding, I've zero experience with Vue - it's my introduction to frameworks and arrays are currently my nemesis. In a recent exercise, I managed to display the first five elements of an array in a table after filt ...

Problem encountered while trying to import npm module in React Native

Working on developing an android app and currently in the process of importing the spotify-web-api-node module. In my index.android.js file, I have added the following line: import SpotifyWebApi from 'spotify-web-api-node'; However, when I try ...

Creating a webpage using webkit technology

As someone new to web development, I am eager to create a website that is user-friendly on both desktops and mobile devices. Recently, I stumbled upon a site with impeccable design and functionality using what appeared to be "screen webkit". I'm curi ...

The HTML video controls in Safari take precedence over the window.name attribute

When using Safari 8.0.5, the controls attribute for the video element will change the value of window.name to "webkitendfullscreen". This is significant because I rely on using window.name to store client-side data in Safari's private mode, where loca ...

Displaying Unicode CSS Font Awesome Icons as Boxes in a React Project

I have incorporated the jPlayer example into a create-react-app. Encountering an issue where font-awesome icons are displaying as boxes in this CodeSandbox illustration. https://codesandbox.io/s/peaceful-heisenberg-d59nz?fontsize=14&hidenavigation=1&a ...

Fast method to verify variable existence in MySQL INSERT statement with PHP

I'm currently in the process of developing a PHP script that will allow users to add items to their shopping basket. Within my shopping basket table, I have fields for userid, product id, session id, notes, and various other details. Some of these fie ...

Error: Placeholder Loading Card malfunctioning

I attempted to incorporate a Placeholder Loading Card into my bootstrap 4 website by adding a sample image, but encountered an issue. The placeholder does not work when the website is loading. Is it supposed to always animate? Does anyone have knowledge ...

Why is this regular expression failing to match German words?

I am attempting to separate the words in the following sentence and enclose them in individual span elements. <p class="german_p big">Das ist ein schönes Armband</p> I came across this: How to get a word under cursor using JavaScript? $(&ap ...

Navigate to a precise point in a video using react hooks in videojs

I am currently working on adding a feature that allows users to skip forward or backward by 15 seconds in a video. However, I am encountering difficulties when it comes to updating and setting the current time accordingly. const videoNode = useRef(null); ...

The cURL command successfully executes the request, however, it fails to work in both Postman and web browsers

A problem arises when the Node Js (express) server responds to requests using cUrl, resulting in an infinite load. However, when requested via Postman or a browser, there are no errors but still faces issues. Despite searching for solutions, none of the s ...

The function of jQuery's .prop('defaultSelected') appears to be unreliable when used in Internet Explorer 9

Below is the code I am currently using: $selects = $('select'); $selects.val( $selects.prop('defaultSelected')); The purpose of this code is to reset the values of all select elements on my webpage. However, I am facing an issue in IE ...

How can you ensure a line stays fixed to the bottom of a box regardless of the text size in SCSS and HTML?

I have a CSS rule that displays a line within a div only when the div is active. The specific SCSS class I am using is: .active-tab:after { content: ''; display: inline-block; height: 4px; width: 100px; right: -7px; background-color: ...

Normalization, perplexed

I'm currently working on implementing normalization in my database design, but I've been reading some explanations online that have left me a bit confused. I want to make sure I'm heading in the right direction with my approach. So far, I h ...

Displaying content conditionally in Vue JS upon the initial page load

I am currently working on a Vue component that is supposed to render the first time a page is opened. However, I am facing some confusion regarding the logic behind this. My approach involves using localStorage to check for an item called 'wasVisited& ...

Laravel Database Seeder Error: 1452 Integrity constraint violation - Unable to add or update a child record due to foreign key constraint failure

I'm currently working on a Twitter clone app using Laravel 5.4 and referencing this tutorial. Now, I want to seed the database with test data. When I input the following command in my terminal: php artisan db:seed --class=TweetsTableSeeder, I encoun ...

The dropdown menu is extending outside the header in a right-to-left (RTL) direction

I have implemented the jQuery code below to prevent the dropdown from extending beyond the header area. It works perfectly in the normal LTR version. However, I need a solution for the RTL version. How can I achieve this? jQuery $('.primary-menu .dr ...

adjust time in jQuery AJAX request when a button is clicked

I have the following code snippet that triggers when a button is clicked. When a user clicks on a button, I want to show a progress bar or waiting image in the browser for 5 seconds. How can I set a timeout and display the progress bar or waiting image wh ...

Error: Unable to locate module - The specified file cannot be resolved when utilizing an external JavaScript library

I am currently integrating a WYSIWYG editor (TUI Editor) into my Angular2+ application. Since there is no official Angular wrapper available, I have decided to create my own based on an existing wrapper. Due to some installation issues with npm, I saved t ...