RE: Dynamically build a form from mySQL table
| From: | Tim Ward | Date: | Wed, 21 Mar 2001 09:25:01 +0000 |
| Subject: | RE: Dynamically build a form from mySQL table | ||
| Groups: | php.general | ||
| Request: | Send a blank email to php-general+get-44910@lists.php.net to get a copy of this message | ||
$result = mysql_db_query("FocusDynamics", "SHOW COLUMNS FROM items");
while($field = mysql_fetch_array($result))
{ $thisfield = $field["field"];
echo("<tr>");
echo("<td>$thisfield</td><td><input type=text ...
name=$thisfield></td>");
echo("</tr>");
}
I'm assuming mysql. You may want to play around with analysing
$field["type"] to get the right input attributes. There may be a slicker
way, but I think this is pretty straight forward and the "SHOW COLUMNS"
query isn't going to be slow.
... also this untested so please treat as pseudo code.
Tim Ward
Senior Systems Engineer
Please refer to the following disclaimer in respect of this message:
http://www.stivesdirect.com/e-mail-disclaimer.html
> -----Original Message-----
> From: Martin E. Koss [mailto:mek@mek.co.uk]
> Sent: 20 March 2001 18:06
> To: php-general@lists.php.net
> Subject: Dynamically build a form from mySQL table
>
>
> Hi,
> I've been trying to figure this out by looking through the code in
> phpMyAdmin but I'm not getting very far. There's probably
> some help about it
> somewhere.
>
> What I want to do is dynamically generate a form where I get
> a table row
> containing the field name in one cell and the input field in
> the next cell,
> for example:
>
> $DatabaseName = "FocusDynamics";
> $TableName = "Items";
>
> // open the table and get all field names, sizes, etc.,
>
> // for each Field name, print something like:
>
> PRINT "<tr>\n";
> PRINT "<td>$FieldName</td>\n";
> PRINT "<td><input type=\"text\" name=\"$FieldName\"
> value=\"$FieldValue\"
> maxlength=\"FieldSize\"></td>\n";
> PRINT "</tr>";
>
> How do I get all this info from the table?
>
> Thanks for any help.
>
>
> Martin E. Koss
> M: 07946-706459
> E: mek@mek.co.uk
>
>