从 PHP 表中自动生成字段名称
从 MySQL 表中自动检索字段名称存在问题。如果可能的话,名称可以与动态创建的文本框一起以这种格式放置吗? :
我到目前为止创建的代码位于下面:
<?php
include "db_connect.php";
$name = mysql_query("SELECT * from users");
$property = mysql_fetch_field($name);
$i = 0;
$result = mysql_query("SHOW COLUMNS FROM users");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
while($i<mysql_num_fields($result))
{
$meta=mysql_fetch_field($name,$i);
$new = $meta->name;
echo "$new: <input type=\"text\" name=\"{$row['Field']}\" size=\"40\"
maxlength=\"256\" /><br>";
$i++;
}
}
}
?>
动态创建的文本框(根据表中的列数)工作正常,但无法生成字段名称!有人可以就此提供建议或帮助吗?谢谢!
There is a problem of automatically retrieving field names from a MySQL table. If possible could the name be placed in this format along with the dynamically created text box? :
The codes that I have created so far are located below:
<?php
include "db_connect.php";
$name = mysql_query("SELECT * from users");
$property = mysql_fetch_field($name);
$i = 0;
$result = mysql_query("SHOW COLUMNS FROM users");
if (!$result) {
echo 'Could not run query: ' . mysql_error();
exit;
}
if (mysql_num_rows($result) > 0) {
while ($row = mysql_fetch_assoc($result)) {
while($i<mysql_num_fields($result))
{
$meta=mysql_fetch_field($name,$i);
$new = $meta->name;
echo "$new: <input type=\"text\" name=\"{$row['Field']}\" size=\"40\"
maxlength=\"256\" /><br>";
$i++;
}
}
}
?>
The Dynamically created text box (according to the number of columns from the table) are working fine but the field names cannot be generated! Can someone please give advice or help on this? Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
下面的代码将获取表列并生成输入列表。在你的代码中有很多无用的东西。您不需要
从用户中选择*
...这是代码
Code below will get table columns and generate the list of inputs. In you code you have a lot of things that are useless. You do not need to
select * from users
...Here is the code
回答:
Answer: