* I have 2 tables in a MySWL database.
* The 2 tables (students/teachers) have different number of fields
* Teachers = 8 fields / Students = 5 fields
* A page for inserting new data into the tables is created.
* The text box appears but without any field names beside the text box.
So now there is a need to allow the "insert" page to auto generate the Field names found within the table to allow the naming of the various text box.
I think that by including the "mysql_fetch_field" function, it can be used to auto generate the field names needed for the PHP page.
Please kindly give some suggestions. Thanks!
Here are my codes:
Code: Select all
<?php
include "db_connect.php";
$name = mysql_query("SELECT * from users");
$property = mysql_fetch_field($result);
$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)) {
echo "$property: <input type=\"text\" name=\"{$row[0]}\" size=\"40\"
maxlength=\"256\" /><br>";
}
}
?>