[英]BOOTSTRAP Table in a PHP Foreach loop
I have som trouble finding out what i am doing wrong. 我很难找出我做错了什么。 I am using Bootstrap Table in a foreach loop
我在foreach循环中使用Bootstrap表
Foreach($fetchSite as $rows)
{
$sname = $rows['name'];
echo "<div class='well'>"
. "<h4>$sname</h4>";
foreach ($fetchDep as $rowd)
{
$depn = $rowd['dep'];
echo "<h5>$depn:</h5>";
foreach($fetchUserdata as $row)
{
$uname = $row['username'];
$team = $row['team'];
$stime = $row['sttime'];
$depna = $row['dep'];
$siten = $row['name'];
if($sname == $siten)
{
if($depn == $depna)
{
echo "<div class='row'>"
. "<div class='table-responsive'>"
. "<table class = 'table table-striped' style='width: 500px;'>"
. "<thead><tr><th>Bruger:</th><th>Team:</th><th>startet:</th></tr></thead>";
echo "<tr><td>".$uname."</td><td>".$team."</td><td>".$stime."</td></tr>";
echo "<tbody>"
. "</tbody>"
. "</table>"
. "</div>"
. "</div>";
}
}
}//end Foreach FetchUSerdata
}// end Foreach Depfetch
echo "</div>";
} // End Foreach FetchSite
The problem is that there are to many Bruger:, Team: and startet 问题在于,有很多Bruger :, Team:和startet
i only want 1 line of Bruger, Team: and startet and then the users listed below. 我只想要1行Bruger,Team:和startet,然后再列出下面的用户。 I know where the problem is:
我知道问题出在哪里:
if($depn == $depna)
{
echo "<div class='row'>"
. "<div class='table-responsive'>"
. "<table class = 'table table-striped' style='width: 500px;'>"
. "<thead><tr><th>Bruger:</th><th>Team:</th><th>startet:</th></tr></thead>";
echo "<tr><td>".$uname."</td><td>".$team."</td><td>".$stime."</td></tr>";
echo "<tbody>"
. "</tbody>"
. "</table>"
. "</div>"
. "</div>";
}
But i dont no how to solve it. 但是我没有解决的办法。 Sorry for my bad english and stupid question.
对不起,我的英语和愚蠢的问题。 Merry Christmas
圣诞节快乐
The only thing you would want to leave inside the foreach is the <tr>
and <td>
sections. 您唯一想留在foreach中的是
<tr>
和<td>
部分。 Leave the <table..>
and <th>
(table headers outside) the foreach that way it will generate a table. 将
<table..>
和<th>
(位于表头之外)留在foreach中,以这种方式将生成表。
Example 例
echo "<div class='row'>"
. "<div class='table-responsive'>"
. "<table class = 'table table-striped' style='width: 500px;'>"
. "<thead><tr><th>Bruger:</th><th>Team:</th><th>startet:</th></tr></thead>";
foreach($fetchUserdata as $row)
{
$uname = $row['username'];
$team = $row['team'];
$stime = $row['sttime'];
$depna = $row['dep'];
$siten = $row['name'];
if($sname == $siten)
{
if($depn == $depna)
{
echo "<tbody>"
."<tr><td>".$uname."</td><td>".$team."</td><td>".$stime."</td></tr>";
. "</tbody>"
}
}
}
echo "</table>"
. "</div>"
. "</div>";
//end Foreach FetchUSerdata
It's really difficult to understand what you're asking, but I think I got the gist. 很难理解您的要求,但我想我的要点是。 The following code example takes an array
以下代码示例采用一个数组
$fetchSite = [
[
'something' => 'a',
'something_else' => 'b'
],
...
]
and turns it into a table 变成一张桌子
something | something_else
----------+---------------
a | b
code: 码:
<table>
<thead>
<tr>
<?php foreach(array_keys($fetchSite[0]) as $column) { ?>
<th><?=$column?></th>
<?php } ?>
</tr>
</thead>
<tbody>
<?php foreach($fetchSite as $row) {
foreach($row as $column) { ?>
<td><?=$column?></td>
<?php }
} ?>
</tbody>
</table>
perhaps that will help you 也许那会帮助你
Foreach($fetchSite as $rows)
{
$sname = $rows['name'];
echo "<div class='well'>"
. "<h4>$sname</h4>";
foreach ($fetchDep as $rowd)
{
$depn = $rowd['dep'];
echo "<h5>$depn:</h5>";
echo "<div class='row'>"
. "<div class='table-responsive'>"
. "<table class = 'table table-striped' style='width: 500px;'>"
. "<thead><tr><th>Bruger:</th><th>Team:</th><th>startet:</th></tr></thead>";
echo "<tbody>";
foreach($fetchUserdata as $row)
{
$uname = $row['username'];
$team = $row['team'];
$stime = $row['sttime'];
$depna = $row['dep'];
$siten = $row['name'];
if($sname == $siten)
{
if($depn == $depna)
{
echo "<tr><td>".$uname."</td><td>".$team."</td><td>".$stime."</td></tr>";
}
}
}//end Foreach FetchUSerdata
echo "</tbody>"
. "</table>"
. "</div>"
. "</div>";
}// end Foreach Depfetch
echo "</div>";
} // End Foreach FetchSite
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.