gpt4 book ai didi

php - 从 DB PHP 生成一个包含 值的表行

转载 作者:行者123 更新时间:2023-11-30 23:47:40 26 4
gpt4 key购买 nike

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

目前我只能在每个 <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>";这没有帮助。

我不断收到 undefined index 错误或所有字段都是单个值。

如果有任何不清楚或需要进一步解释的地方,请告诉我,我会尽量让我的问题更清楚。

任何帮助都会很棒,

谢谢

最佳答案

尝试:

$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>";
}

关于php - 从 DB PHP 生成一个包含 <td> 值的表行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29902649/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com