Hi There! 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!