RE: [PHP] listing table columns?
| From: | John W. Holmes | Date: | Tue, 22 Apr 2003 23:53:11 +0000 |
| Subject: | RE: [PHP] listing table columns? | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-144924@lists.php.net to get a copy of this message | ||
> I need to create a dynamic form that lists all of the columns from a
> table. The user then chooses the columns he wishes to be displayed
and
> submits the form. The data is then displayed - only the data from the
> fields the user chose.
>
> Is there a way, using PHP or MySQL, to list all of the fields in a
table?
$query = 'SHOW COLUMNS FROM table';
$result = mysql_query($query);
while($column = mysql_fetch_row($result))
{ echo $column[0]; }
or
while($column = mysql_fetch_assoc($result))
{ echo $column['Field']; }
or
$query = 'DESC table';
...
or use mysql_field_name()
or... well, maybe that's enough. :)
Enjoy...
---John W. Holmes...
PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/