[英]PHP Splitting data into 2 columns into an html table not working
Hey guys I'm back and I feel like I'm making a really stupid error in my code but I can't seem to find it. 大家好,我回来了,我觉得我在代码中犯了一个非常愚蠢的错误,但我似乎找不到。 What I am trying to do is split data retrieved from a mysql table into two columns inside an html table. 我正在尝试将将从mysql表中检索的数据拆分为html表中的两列。 So far I got it working...sort of. 到目前为止,我已经开始工作了。 The problem I am having is the data keeps replicating to both rows in the table versus being an individual entry in each cell. 我遇到的问题是数据一直复制到表的两行,而不是每个单元格中的单独条目。 I have used googled and searched these forms and can't seem to see where I am making the error. 我用google搜索过这些表格,但似乎看不到我在哪里出错。 Below is the code 下面是代码
// Build the table
echo '
<table>
<tr>
';
// Build the headers
for ($x = '1'; $x <= '2'; $x++)
echo '
<td>Truck</td>
<td>Home Base</td>
<td>Client</td>
<td>Job Details</td>
<td>Crew</td>
';
// Close off headers
echo '</tr>';
// Fetch the table contents if the rigs are active
while($row = mysqli_fetch_array($truck_full_query)) {
for ($y = '1'; $y <= '1'; $y++):
echo '<tr>';
for ($z = '1'; $z <= '2'; $z++):
echo '<td>' . $row['model'] . ' #' . $row['position'] . '<br>' . $row['unit_number'] . '</td>';
echo '<td>' . $row['dispatch_location'] . '</td>';
// Get client information
echo '<td> </td>';
// Get Job Details
echo '<td> </td>';
// Get Crew
echo '<td> </td>';
endfor;
echo '</tr>';
endfor;
}
// Close table
echo '</table>';
// Build the table
echo '<table><tr>';
// Build the headers
echo '<td>Truck</td><td>Home Base</td><td>Client</td><td>Job Details</td><td>Crew</td>';
echo '<td>Truck</td><td>Home Base</td><td>Client</td><td>Job Details</td><td>Crew</td>';
echo '</tr>';
$data = mysqli_fetch_all($truck_full_query);
$i = 0;
$t = sizeof($data);
for (; $i < $t; $i += 2) {
echo '<tr>';
$left_row = $data[$i];
echo '<td>' . $left_row['model'] .'</td><td>...</td><td>...</td><td>...</td><td>...</td>';
$right_row = $data[$i + 1];
echo '<td>' . $right_row['model'] .'</td><td>...</td><td>...</td><td>...</td><td>...</td>';
echo '</tr>';
}
echo '</table>
And don't forget to check if the last $right_row
exists. 并且不要忘记检查最后一个$right_row
存在。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.