繁体   English   中英

PHP将数据分为两列到html表中不起作用

[英]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>&nbsp;</td>';
            // Get Job Details
            echo '<td>&nbsp;</td>';
            // Get Crew
            echo '<td>&nbsp;</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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM