[英]output an Array with same values
I have a SQL Query result (array): "title", "content" and "name" Here is my var_dump:我有一个 SQL 查询结果(数组):“标题”、“内容”和“名称” 这是我的 var_dump:
array(28) {
[0]=>
array(3) {
["title"]=>
string(10) "Basis Task"
["content"]=>
string(43) "https://www.wrike.com/open.htm?id=440908999"
["name"]=>
string(14) "Christian Wahl"
}
[1]=>
array(3) {
["title"]=>
string(10) "Basis Task"
["content"]=>
string(5) "MySQL"
["name"]=>
string(14) "Christian Wahl"
}
[2]=>
array(3) {
["title"]=>
string(4) "Test"
["content"]=>
string(3) "PHP"
["name"]=>
string(14) "Christian Wahl"
}
[3]=>
array(3) {
["title"]=>
string(4) "Test"
["content"]=>
string(3) "PHP"
["name"]=>
string(14) "Christian Wahl"
}
[4]=>
array(3) {
["title"]=>
string(10) "Basis Task"
["content"]=>
string(7) "content"
["name"]=>
string(9) "Elena Ott"
}
(I cut off the end of the array to make it a little clearer to see) These are Tasks who are assigned to a User. (我切断了数组的末尾,以便看得更清楚)这些是分配给用户的任务。
Now i want to output the "Name" (panel-heading) and the "title" and "content" (panel-body).现在我想要 output “名称”(面板标题)以及“标题”和“内容”(面板主体)。
It should look smth like this but for each given name:它应该看起来像这样,但对于每个给定的名称:
how it should look like它应该是什么样子
I tried to find a solution on my own, but without success:( I hope u can help me?我试图自己找到解决方案,但没有成功:( 我希望你能帮助我吗?
thx a lot多谢
-Taddl -Taddl
just loop on your data and render it只是循环你的数据并渲染它
$data = [];
foreach ($databaseResult as $row) {
$data[$row['name']][] = $row;
}
foreach($data as $name => $stuff) {
echo $name . '<br>';
foreach($stuff as $row) {
echo $row["title"] . ':' . $row["content"] . '<BR>';
}
}
You can use foreach loop.您可以使用 foreach 循环。 As example:
例如:
foreach($yourarrayvariable as $data)
{
echo "<tr>";
echo "<td class='heading'>".$data['name']."</td>";
echo "<div class='content'>";
echo "<td>".$data['title']."</td>";
echo "<td>".$data['content']."</td>";
echo "</div>";
echo "</tr>";
}
And create your desired template look classes as per your need inside foreach.并根据您在 foreach 中的需要创建所需的模板外观类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.