php - 如何在同一个文件中选择多个单词,它们具有相同的文件 wav?
问题描述
ii想通过文件链接选择信息,例如在第一行的数据库中:
文件链接:src/java/son3.wav | 词:邮寄
DB 中的第二行:文件链接:src/java/son3.wav | 词:smtp
DB 中的第 3 行:文件链接:src/java/son2.wav | 词:服务器
我想在 html.twig :: 中显示这样的内容
编号:1 | 文件链接:src/java/son3.wav | word : 邮寄 , smtp
id : 2 | 文件链接:src/java/son2.wav | 词:服务器
以便选择数据库中具有相同文件链接的所有单词,我希望这能解释我所追求的。
我正在使用 symfony 3.4,这就是它在我的界面中的显示方式:
https://i.stack.imgur.com/7EQ63.jpg
这是我在 DB 中的表的图片:
https://i.stack.imgur.com/MEYaJ.jpg
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>
这是文件控制器的代码:
public function IndexAction()
{
////////////////////////////////////////////
$em = $this->getDoctrine()->getManager();
$resultats = $em->getRepository('AppBundle:Indexe')->findAll();
return $this->render('userfiles/result.html.twig', array(
'resultats' => $resultats,
));
}
解决方案
我认为仅使用 DQL 查询是不可能的,后处理可以提供帮助:
公共函数 IndexAction() {
////////////////////////////////////////////
$em = $this->getDoctrine()->getManager();
$tmp = $em->getRepository('AppBundle:Indexe')->findAll();
$tmp2 = [];
foreach ($tmp as $v) {
if (!isset($resultats[$v->getIndexeFichier()->getFichierUrl()])) {
$resultats[$v->getIndexeFichier()->getFichierUrl()] = [];
}
$resultats[$v->getIndexeFichier()->getFichierUrl()][] = $v->indexeMot()->getMotValeur();
}
$resultats = [];
$i = 1;
foreach ($tmp2 as $k=>$v) {
$resultats[] = ['id' => $i++, 'fichierUrl' => $k, 'motValeur' => join(', ', $v)];
}
return $this->render('userfiles/result.html.twig', array(
'resultats' => $resultats,
));
}
并在模板中
....
{% for result in resultats %}
<tr>
<td><a href="{{ path('result', { 'id': result.id }) }}">{{ result.id }}</a></td>
<td>{{ result.fichierUrl }}</td>
<td>{{ result.motValeur }}</td>
</tr>
{% endfor %}
....
如果你的数据库是mysql,你可以尝试使用GROUP_CONCAT()
函数
推荐阅读
- php - Woocommerce 外部/附属产品 URL 中的自定义查询字符串
- kotlin - Kotlin 主构造函数调用辅助构造函数
- excel - Excel 嵌套的 IF 将 FALSE 值串在一起并呈现 #VALUE
- c - char 指针的内存分配
- python - 无法使用 ctype 在 python 中加载 .dll
- php - 从 OneToMany 类别实体上的 Doctrine 数据库结果生成多维数组的递归函数
- python - 不再满足条件时调用具有 lock.aquire() 的函数
- android - 删除 TextInput 下划线 React-Native
- google-sheets - 按降序使用 SORT() 时排除空单元格
- azure-functions - Azure 持久功能扩展