silex 循环一个 sql 语句覆盖另一个语句

silex loop one sql statement over another one

我必须从数据库中按组获取团队成员。

我的数据库看起来像:

table team_groups:

table team_member:

我有一个 twig 模板,其中 team_member 由这样的组显示:

<div class="row row-centered">
      <h3 class="text-center">{{team_group.name}}</h3>

      <div class="col-xs-6 col-centered col-fixed">
        <div class="item">
          <div class="team-member text-center">
            <span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{team_member.imagepath}}"
                       alt="{{team_member.name}}"></span>

            <h3>{{team_member.name}}</h3>

            <p>{{team_member.description}}</p>
          </div>
        </div>
      </div>
      <div class="col-xs-6 col-centered col-fixed">
        <div class="item">
          <div class="team-member text-center">
            <span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{team_member.imagepath}}"
                       alt="{{team_member.name}}"></span>

            <h3>{{team_member.name}}</h3>

            <p>{{team_member.description}}</p>
          </div>
        </div>
      </div>
      <div class="col-xs-6 col-centered col-fixed">
        <div class="item">
          <div class="team-member text-center">
            <span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{team_member.imagepath}}"
                       alt="{{team_member.name}}"></span>

            <h3>{{team_member.name}}</h3>

            <p>{{team_member.description}}</p>
          </div>
        </div>
      </div>
    </div>

但我不知道如何在我的控制器中将 team_member 循环到 team_groups 上。

我是这样开始的:

$teamGroups = $app['db']->fetchAll('SELECT * team_groups');
$teamMembers = $app['db']->fetchAll('SELECT * team_members');

但不知道如何继续。

请帮忙

哦,是的,树枝真的很好……

我以为我必须link控制器中的对象,但现在我只是写了:

{% for teamGroup in teamGroups %}
      <div class="row row-centered">
        <h3 class="text-center">{{ teamGroup.name }}</h3>
        {% for teamMember in teamMembers %}
          {% if teamMember.team_group_id is same as(teamGroup.id) %}
            <div class="col-xs-6 col-centered col-fixed">
              <div class="item">
                <div class="team-member text-center">
            <span><img class="img-team" src="{{ app.request.basepath }}/img/team/{{ teamMember.image }}"
                       alt="{{ teamMember.name }}"></span>

                  <h3>{{ teamMember.name }}</h3>

                  <p>{{ teamMember.description }}</p>
                </div>
              </div>
            </div>
          {% endif %}
        {% endfor %}
      </div>
    {% endfor %}

这对我有用:-)