php怎么生成动态的表格,表头和数据都是动态的
1个回答
展开全部
可以先放把表头信息放到一个集合里,
然后把数据放入一个二维数组或二维的容器里
例如 :
后台
String[] tis = {"7.1","7.2","7.3"};
List<String[]> data = new ArrayList<String[]>();
data.add(new String[]{"1","2","3"});
data.add(new String[]{"4","5","6"});
data.add(new String[]{"7","8","9"});
request.setAttribute("tis", tis);
request.setAttribute("data", tis);
Jsp:
<table>
<!-- 表头 -->
<tr>
<c:forEach items="tis" var="ti">
<td>${ti}</td>
</c:forEach>
</tr>
<!-- 数据 -->
<c:forEach items="data" var="ds">
<tr>
<c:forEach items="ds" var="d">
<td>${d}</td>
</c:forEach>
</tr>
</c:forEach>
</table>
然后把数据放入一个二维数组或二维的容器里
例如 :
后台
String[] tis = {"7.1","7.2","7.3"};
List<String[]> data = new ArrayList<String[]>();
data.add(new String[]{"1","2","3"});
data.add(new String[]{"4","5","6"});
data.add(new String[]{"7","8","9"});
request.setAttribute("tis", tis);
request.setAttribute("data", tis);
Jsp:
<table>
<!-- 表头 -->
<tr>
<c:forEach items="tis" var="ti">
<td>${ti}</td>
</c:forEach>
</tr>
<!-- 数据 -->
<c:forEach items="data" var="ds">
<tr>
<c:forEach items="ds" var="d">
<td>${d}</td>
</c:forEach>
</tr>
</c:forEach>
</table>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询