[英]PHP Splitting data into 2 columns into an html table not working
大家好,我回來了,我覺得我在代碼中犯了一個非常愚蠢的錯誤,但我似乎找不到。 我正在嘗試將將從mysql表中檢索的數據拆分為html表中的兩列。 到目前為止,我已經開始工作了。 我遇到的問題是數據一直復制到表的兩行,而不是每個單元格中的單獨條目。 我用google搜索過這些表格,但似乎看不到我在哪里出錯。 下面是代碼
// 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>
並且不要忘記檢查最后一個$right_row
存在。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.