如何在一个表中正确放置多个查询的结果

时间:2014-05-02 08:43:29

标签: html-table coldfusion cfloop cfoutput

<center><h2>Kaarten overzicht</h2></center>

<table border="1" id="table">
    <tr>
        <th>Patiente Naam</th>
        <th>Arts</th>
        <th>Huisarts</th>
        <th>Diagnose</th>
    </tr>

    <!--- Alle informatie van patiente in een table zetten. --->
    <cfloop query="VARIABLES.overzicht">
        <cfoutput>
            <tr>
                <td>#Voornaam# #Achternaam#</td>
        </cfoutput>
    </cfloop>
    <cfloop query="VARIABLES.overzichtArtsen">
        <cfoutput>
                <td>#Voornaam# #Achternaam#</td>
        </cfoutput>
    </cfloop>
    <cfloop query="VARIABLES.overzichtHuisartsen">
        <cfoutput>
                <td>#Voornaam# #Achternaam#</td>
        </cfoutput>
    </cfloop>
    <cfloop query="VARIABLES.overzichtDiagnose">
        <cfoutput>
                <td>#Type#</td>
            </tr>   
        </cfoutput>
    </cfloop>
</table>

它没有按照我希望结果出错的方式出现.. 我将ColdFusion与框架Fusebox一起使用。查询为SELECT * FROM [table_name];

请帮助..

2 个答案:

答案 0 :(得分:1)

@Duncan关于加入表可能是最佳解决方案是正确的,但这里是关于如何在一个循环中引用多个查询的问题的答案。

这假设您的查询都返回了相同数量的记录。

<center><h2>Kaarten overzicht</h2></center>

<table border="1" id="table">
    <tr>
        <th>Patiente Naam</th>
        <th>Arts</th>
        <th>Huisarts</th>
        <th>Diagnose</th>
    </tr>

    <!--- Alle informatie van patiente in een table zetten. --->
    <cfoutput>
    <cfloop query="VARIABLES.overzicht">
    <tr>
        <td>#Voornaam# #Achternaam#</td>
        <td>
          #VARIABLES.overzichtArtsen.Voornaam[CurrentRow]#
          #VARIABLES.overzichtArtsen.Achternaam[CurrentRow]#
        </td>
        <td>
          #VARIABLES.overzichtHuisartsen.Voornaam[CurrentRow]#
          #VARIABLES.overzichtHuisartsen.Achternaam[CurrentRow]#
        </td>
        <td>
          #VARIABLES.overzichtDiagnose.Type[CurrentRow]#
        </td>
    </tr>
    </cfloop>
    </cfoutput>
</table>

查询可以作为结构访问,每个列都有键,每列都是一个值数组。 CurrentRow是您当前在cfloop中循环的行的索引。

答案 1 :(得分:0)

Duncan关于加入表格的评论是有效的,但即使您遵循它,您可能仍会遇到问题,因为您在不同的循环中有开始和结束标记。

您的代码首先创建一个包含4个单元格的表格行。然后你在循环中有一个开始标记,但没有结束标记。您现在的格式错误,这就是为什么您的显示不是您所希望的。

很难建议替代代码,因为它并不完全清楚你的最终输出应该是什么样子。