【发布时间】:2020-12-08 00:54:16
【问题描述】:
如果测试结果为阳性,我正在尝试创建用户年龄表。目前我让它工作,但对于每个循环,它都会创建另一行并显示结果。我正在尝试将 1 行的数字相加。我不太确定该怎么做。下面是一张桌子的图片。
下面是我创建的用于获取年龄并确保它在年龄范围之间的代码。
<!-- Infection rate per Age Group -->
<c:set var="count2" value="0"/>
<table>
<tr>
<th>Under 20</th>
<th>20-29</th>
<th>30-39</th>
<th>40-49</th>
<th>50-59</th>
<th>60-69</th>
<th>Over 70</th>
</tr>
<c:forEach items="${results}" var="result">
<c:set var="neg" value="Positive"/>
<!-- Set age bounds -->
<c:set var="u20" value="0"/>
<c:set var="b2029" value="0"/>
<c:set var="b3039" value="0"/>
<c:set var="b4049" value="0"/>
<c:set var="b5059" value="0"/>
<c:set var="b6069" value="0"/>
<c:set var="o70" value="0"/>
<c:set var="age" value="${result.age}"/>
<c:set var="pos" value="${result.testResult}"/>
<c:if test="${neg eq pos}">
<!-- Check if age group is in boundaires -->
<c:if test="${age<20}">
<c:set var="u20" value="${u20 + 1 }"/>
</c:if>
<c:if test="${age >=20}">
<c:if test="${age <=29 }">
<c:set var="b2029" value="${b2029 + 1 }"/>
</c:if>
</c:if>
<c:if test="${age >=30}">
<c:if test="${age <=39 }">
<c:set var="b3039" value="${b3039 + 1 }"/>
</c:if>
</c:if>
<c:if test="${age >=40}">
<c:if test="${age <49}">
<c:set var="b4049" value="${b4049 + 1 }"/>
</c:if>
</c:if>
<c:if test="${age >=50}">
<c:if test="${age <=59 }">
<c:set var="b5059" value="${b5059 + 1 }"/>
</c:if>
</c:if>
<c:if test="${age >=60}">
<c:if test="${age <69 }">
<c:set var="b6069" value="${b6069 + 1 }"/>
</c:if>
</c:if>
<c:if test="${age >70}">
<c:set var="o70" value="${o70 + 1 }"/>
</c:if>
</c:if>
<tr>
<td>${u20}</td>
<td>${b2029}</td>
<td>${b3039}</td>
<td>${b4049}</td>
<td>${b5059}</td>
<td>${b6069}</td>
<td>${o70}</td>
</tr>
</c:forEach>
</table>
因此,我不希望每个用户有一行(就像现在一样),我只想要 1 个单行,所有年龄相加 - 例如30-39 类别有 2 个正面,所以这应该是 2 而不是 1 和 1。谢谢您的帮助
【问题讨论】: