gpt4 book ai didi

php - 如何回显列的名称

转载 作者:太空宇宙 更新时间:2023-11-03 12:34:07 25 4
gpt4 key购买 nike

如何回显列的名称?。我能够选择并回显内容 (td),但我不知道如何在 th 中“加载值”。我的意思是从 MySql 数据库动态加载。

我想从数据库 eee 的 td 所在的位置“加载值”。我要显示字段名:id,a,b,c

<table>

<tr>
<th><input class="gris" type="text" name="a" value="load value"/></td>
<th><input class="gris" type="text" name="b" value="load value"/></td>
<th><input class="gris" type="text" name="c" value="load value"/></td>
<th><input class="gris" type="text" name="d" value="load value"/></td>
</tr>

<?php
$result = mysql_query("SELECT * FROM eee");
while($row = mysql_fetch_array($result)) {
?>
<tr>
<td> <input class="blanc" type="text" name="num" value="<?php echo $row['id']?>"/> </td>
<td><input class="blanc" type="text" name="primer" value="<?php echo $row['a']?>"/></td>
<td><input class="blanc" type="text" name="segon" value="<?php echo $row['b']?>"/></td>
<td><input class="blanc" type="text" name="segon" value="<?php echo $row['c']?>"/></td>
</tr>

<?php } ?>

</table>

最佳答案

在 $row 数组上使用 for each 来获取键/值对。键应包含表中的列名。请注意,mysql_fetch_array 的默认值返回一个同时具有关联值和索引值的数组,以防万一您遇到某种意外问题。但我 90% 确定您所要做的就是使用 $key => $value 组合的 foreach,如下所示:

http://us3.php.net/manual/en/control-structures.foreach.php

这是 mysql_fetch_array 上的页面: http://php.net/manual/en/function.mysql-fetch-array.php

更明确的解释:

foreach ($row as $key => $value) {
/* echo your table row with the $key and $value here. */
}

关于php - 如何回显列的名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14037903/

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