【发布时间】:2015-01-10 20:54:48
【问题描述】:
我的所有数据都存储在数组中
<div class="box">
<div class="box-header">
<h3 class="box-title">History Page Station Number: <? php if($_POST){ $id; }?> </h3>
</div><!-- /.box-header -->
<div class="box-body table-responsive">
<table id="example2" class="table table-bordered table- hover">
<thead>
<tr>
<th> Station Name</td>
<th> Country </th>
<th> Date </th>
<th> Timestamp </th>
<th> Temperature(celcius) </th>
<th> Rainfall(mm)</th>
<th> Windspeed(km/h)</th>
</tr>
</thead>
<tbody>
<!-- loop displaying all data -->
<?php
if($_POST){
$cols = 1;
for ($i=1; $i < count($wind); $i++)
{
echo "<tr>";
for ($c=0; $c<$cols; $c++)
{
echo "<td>".$station->name."</td>";
echo "<td>".$station->country."</td>";
echo "<td>".$date[$i]."</td>";
echo "<td>".$time[$i]."</td>";
echo "<td>".$temp[$i]."</td>";
echo "<td>".$rain[$i]."</td>";
echo "<td>".$wind[$i]."</td>";
}
echo "</tr>";
}
}
?>
</tbody>
<tfoot>
<tr>
<th> Station Name</td>
<th> Country </th>
<th> Date </th>
<th> Timestamp </th>
<th> Temperature(celcius) </th>
<th> Rainfall(mm)</th>
<th> Windspeed(km/h)</th>
</tr>
</tfoot>
</table>
</div><!-- /.box-body -->
</div><!-- /.box -->
当我检查输出时,它在第一行的显示元素[0]
Element[0] in 2nd row
Element[1] in 3rd
Element[0] in 4
Element[1] in 5
Element[2] in 6 etc
它再次从第一个元素开始并添加 1.. 我不知道我做错了什么。
我的数组中有 22 个不同的元素
【问题讨论】:
-
你有一个额外的空间:
<? php if($_POST){ $id; }?>首先删除它。 -
$station->name和station->country来自哪里? -
删除整个东西,这不会什么都不做,或者在id中添加
echo。 -
发布的代码没有明显问题。可能是您之前错误地填充了数组...
-
@cuSK 来自我的控制器。连接数据库并获取国家和电台名称
标签: php html arrays html-table