gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 04:57:55 25 4
gpt4 key购买 nike

所以这是我的问题,我正在从数据库中提取数据到我的网站中。我的数据库中需要显示的键/属性(列)是 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com