javascript - Coldfusion 将数据循环到多个列和行中

标签 javascript mysql css sql coldfusion

所以这是我的问题,我正在从数据库中提取数据到我的网站中。我的数据库中需要显示的键/属性(列)是 PostedDate、DataImage 和 Source。我希望它们作为一个 div 输出,顶部是发布日期,中间是图像,底部是源代码,我必须这样做。但是,我需要它们遍历 3 列并每 3 列创建一个新行,以便它被分开,而不仅仅是一个大列或行。

所以它会像这样 [PostedDate, Image, Source] [PostedDate, Image, Source] 等 3 列多行

这就是我试图让它看起来像的东西:

enter image description here

这是我当前的代码,但是当我刷新网页时,它给我一个 404 或 500 错误:

        <!--- set the number of colums you wish 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 to the next record in this example if we started on the first cell of the first row it would be 1(a), then 4(d), then 7(g) and so on if this was the firs cell on the second row it would be 2(b), 5(e), 8(h), continue... --->
        <cfset output = output + totalRows>
    </td>
    </cfloop>
    <!--- this little bit tells where to start the next row. if we just finished the first row output would be 2(b) --->
    <cfset output = thisRow + 1>
</tr>
</cfloop>

最佳答案

这种方法可能更简单。

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

关于javascript - Coldfusion 将数据循环到多个列和行中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40288853/

相关文章:

html - 清除 span 和 table 之间的间隙

javascript - Angular 一次请求页面上的三个部分

php - 无法将 uniqid() 值插入 MySQL 数据库

php - 关系 laravel 中的链接表

html - 使用 CSS3 和 HTML5 向下滑动菜单栏

css - 背景:50% 50%/封面;这是什么意思?

javascript - 在 AngularJS 中顺序运行 $http 请求

javascript - 禁用滚动上的悬停以防止浏览器重绘

javascript - 如何显示在对象中声明为 url 且这些对象存储在数组中的图像?

php - 时事通讯注册页面(PHP 和 MySQL)