繁体   English   中英

使用生成表行 <td> DB PHP中的值

[英]Generate a table row with <td> values from DB PHP

我正在尝试创建一个动态制作的表,该表将在每行中显示多个下拉列表,这些下拉列表具有存储在数据库中的先前选择的值。

目前,我只能在每个<td>显示正确的值。

//$query..               
$data = mysqli_query($dbc, $query);

echo"<table>
        <tr>
        <th>Component</th>
        <th>Component Type</th>
        <th>Component Thickness</th>
        </tr>";

while ($row = mysqli_fetch_array($data)) { //while I have rows..

    //add column values to an array
    $facSecComponentID[] = $row['facility_section_components_id'];
    $facSecComponent[] = $row['roof_component_id'];
    $facSecComponentType[] = $row['roof_component_type_id'];
    $facSecComponentThickness[] = $row['component_thickness'];

    //try to loop through each index of each row and get the DB value..
    //eventually use this value to assign a selected index within the drop down list
    foreach ($row as $componentIndex => $selectedComponent) {
        echo "<tr>";
        echo "<td>" . $facSecComponent[$selectedComponent] . "</td>";
        echo "<td>" . $facSecComponentType[$selectedComponent] . "</td>";
        echo "<td>" . $facSecComponentThickness[$selectedComponent] . "</td>";
        echo "</tr>";   
    }
}

echo "</table>";

我无法在此处正确显示所需的值,我也尝试执行以下操作: "<td>" . $componentIndex[$selectedComponent] . "</td>"; "<td>" . $componentIndex[$selectedComponent] . "</td>"; 这没有帮助。

我不断收到未定义的索引错误,或者所有字段都是单个值。

让我知道是否有任何不清楚的地方或需要进一步说明的问题,我将尽力使我的问题更清楚。

任何帮助都会很棒,

谢谢

尝试:

$facSecComponentID = array();
$facSecComponent = array();
$facSecComponentType = array();
$facSecComponentThickness = array();

while ($row = mysqli_fetch_array($data)) {
    $facSecComponentID[] = $row['facility_section_components_id'];
    $facSecComponent[] = $row['roof_component_id'];
    $facSecComponentType[] = $row['roof_component_type_id'];
    $facSecComponentThickness[] = $row['component_thickness'];
}

$numItems = mysqli_num_rows($result);

for($i=0;$i<$numItems;$i++){
    echo "<tr>";
    echo "<td>{$facSecComponent[$i]}</td>";
    echo "<td>{$facSecComponentType[$i]}</td>";
    echo "<td>{$facSecComponentThickness[$i]}</td>";
    echo "</tr>";   
}

最好连接一个像

$this->Table ="<table>";
while($MyRow = mysqli_fetch_array($fect)){
$this->Table .="<tr><td>".$MyRow['data']."</td></tr>";

}
$this->Table .="</table>";

return $this->Table ;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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