【发布时间】:2019-07-18 03:45:42
【问题描述】:
我使用我的代码来填充表格: 我在县牢房和区牢房有两条记录 这是我的代码:
<table>
<tr>
<th>town</th>
<th>counties</th>
<th>districts</th>
<th>number doctor</th>
</tr>
{% for item in locality %}
<tr>
<td>{{ item.name }}</td>
<td>
{% for list in item.regions %}
{{ list.county}}
{% endfor %}
</td>
<td>
{% for list in item.regions %}
{{ list.code}}
{% endfor %}
</td>
<td>{{ item.regions|default([])|length }}</td>
</tr>
{% endfor %}
</table>
这是我的桌子:
+--------+---------+----------+---------------+
| town |counties |districts | number doctor |
+--------+---------+----------+---------------+
| Adan | Afla | avo | |
| | kent | joly | 2 |
+--------+---------+----------+---------------+
但是,我希望表格显示变为:
+----------+---------+----------+---------------+
| town |counties |districts | number doctor |
+----------+---------+----------+---------------+
| Adan | Afla | avo | 2 |
+----------+---------+----------+---------------+
| Adan | kent | joly | 2 |
+----------+---------+----------+---------------+
如何解决这个问题?
注意:请原谅我的英语,
提前谢谢你
【问题讨论】:
-
在返回这些数据时是否使用 distinct?我认为问题在于您的 PHP 或 MySQL 查询,而不是树枝。您的视图代码很好
-
@habibun 不,我的查询中没有使用 distinct
-
您是否尝试过使用表格边框?
-
@habibun 是的,我使用了表格边框,我在县单元格和地区单元格中有两条记录(我的第一个表格)
标签: symfony twig symfony-2.1