如何在一个原始表中选择信息

时间:2019-05-02 23:15:22

标签: sql symfony

嗨,我想通过文件链接选择信息,例如 在数据库的第一行:

file link :  src/java/son3.wav | word : mailing 

secund line in DB : file link : src/java/son3.wav  | word: smtp
3rd line in DB  : file link : src/java/son2.wav | word : server

我想在html.twig ::

中显示
id : 1 | file link : src/java/son3.wav | word : mailing , smtp
id : 2 | file link : src/java/son2.wav | word : server

以便选择数据库中具有相同文件链接的所有单词,我希望这可以解释我的目的。

我正在使用symfony 3.4 这就是它在我的界面中显示的方式:

https://i.imgur.com/9roxlOA.jpg

这是我在DB中的表的图片:

enter image description here

this is the code of file twig :

  <table  class="table table-striped">
          <thead>
              <tr>
                 <th>Id</th>
                  <th>File Link</th>
                  <th>Words</th>

              </tr>
          </thead>
          <tbody>

          {% for result in resultats %}
                <tr>
                  <td><a href="{{ path('result', { 'id': result.id }) }}">{{ result.id }}</a></td>
                  <td>{{ result.indexeFichier.fichierUrl }}</td>
                  <td>{{ result.indexeMot.motValeur }}</td>




              </tr>
          {% endfor %}
          </tbody>
      </table>



and this is the code of file controller :

  public function IndexAction()
    {


      ////////////////////////////////////////////
      $em = $this->getDoctrine()->getManager();
      $resultats = $em->getRepository('AppBundle:Indexe')->findAll();
      return $this->render('userfiles/result.html.twig', array(
          'resultats' => $resultats,
      ));

    }

}

1 个答案:

答案 0 :(得分:1)

随后将结果压缩在纯PHP中。

<li>

然后在视图中根据需要将它们分开:

.days li.active

PS:如果您使用Symfony Profiler,则您会发现$viewResults = []; foreach ($resultatas as $result) { if (!isset($viewResults[$result->getIndexeMot()->getMotValeur())]) { $viewResults[$result->getIndexeMot()->getMotValeur()] = ['id' => $result->getId(), 'motValeurs' => []]; } $viewResults[$result->getIndexeMot()->getMotValeur()]['motValeurs'][] = $result->getIndexeFichier()->getFichierUrl(); } 的使用可能会为每个结果添加两个附加查询,因为该结果未正确结合。最好将结果直接存储在{% for key, result in resultats %} <tr> <td><a href="{{ path('result', { 'id': result.id }) }}">{{ result.id }}</a></td> <td>{{ result.indexeFichier.fichierUrl }}</td> <td> {% for motValeur in result.motValeurs %} {{ result.indexeMot.motValeur }} {% endfor %} </td> </tr> {% endfor %} 中,或通过以下查询将其他两个表连接起来:findAll()