[英]Populate HTML table with SQL data and PHP
I am trying to populate a table using aa few loops.我正在尝试使用一些循环来填充表格。
First loop fills up the table headers with users in a row, no problem with that.第一个循环用用户连续填充表头,没问题。
The problem is populating tds as rows with the right ticket number.问题是将 tds 填充为具有正确票号的行。
I can get all numbers in an order column in a single td, which is not how it should work我可以在单个 td 中获取订单列中的所有数字,这不是它应该如何工作
Something like this,像这样的东西,
---------------------
user1 | user2 | user3
---------------------
00001 | 00004 | 00007
00002 | 00005 | 00008
00003 | 00006 | 00009
---------------------
and it should be,应该是,
---------------------
user1 | user2 | user3
---------------------
00001 | 00004 | 00007
---------------------
00002 | 00005 | 00008
---------------------
00003 | 00006 | 00009
---------------------
You get the idea.你明白了。
The this is the code I am using for that,这是我为此使用的代码,
<table class="table table-hover">
<thead>
<tr>
<th scope="row">
<?php
$userName = functionName();
for ($userName->rewind(); $userName->pointer < $userName->size; $userName->next()) {
$record = $userName->current();
$firstName = $record->fields->FirstName;
?>
<th><?php echo $firstName; ?></th>
<?php } ?>
</th>
</tr>
</thead>
<tbody>
<tr>
<th scope="row">
<?php
for ($userName->rewind(); $userName->pointer < $userName->size; $userName->next()) {
$record = $userName->current();
$firstName = $record->fields->FirstName;
?>
<td>
<?php
$userCase = functionCase($firstName);
for ($userCase->rewind(); $userCase->pointer < $userCase->size; $userCase->next()) {
$record = $userCase->current();
$caseNumber = $record->fields->CaseNumber;
$status = $record->fields->Status;
echo $caseNumber;
?>
<?php }
?>
</td>
<?php } ?>
</th>
</tr>
</tbody>
</table>
I think I might be using the for wrong logic and loops for that part.我想我可能在那个部分使用了错误的逻辑和循环。
Any ideas how to achieve the proper table result?任何想法如何实现正确的表格结果?
I think you are using an incorrect HTML table layout.我认为您使用的 HTML 表格布局不正确。
You have a td inside a th, which is not allowed as far as I know.你在 th 中有一个 td,据我所知这是不允许的。 If you want to display your data in several rows, you have to create a tr for every row.
如果要在多行中显示数据,则必须为每一行创建一个 tr。 The trs can then contain th and td items.
然后 trs 可以包含 th 和 td 项目。 For a valid table layout, please refer to http://www.w3schools.com/tags/att_th_scope.asp
有关有效的表格布局,请参阅http://www.w3schools.com/tags/att_th_scope.asp
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.