dynamic dropdown
Moderator: General Moderators
dynamic dropdown
I am trying to create a dropdown list populated from the headers of a mysql table, i.e. there is name, order_id, webpage_url... and so on. I know I can select * from and iterate through results with an option statement echoed out but I don't want the data, just the names of the rows. Is that possible, if so can anyome give me a little insight please? Thank you in advance.
Re: dynamic dropdown
ok....here is the mysql query to get all columns name for any table....
use above query to get result and then create your dynamic drop down.
Code: Select all
SELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='<YOUR TABLE NAME>';Re: dynamic dropdown
If you pull the field names from INFORMATION_SCHEMA.COLUMNS, you must specify the TABLE_SCHEMA. Otherwise, the query will return field names from all databases that have a table with the specified name.
Another way to access field names is with
Code: Select all
SELECT `COLUMN_NAME` FROM `INFORMATION_SCHEMA`.`COLUMNS` WHERE `TABLE_SCHEMA` = 'my_database' AND `TABLE_NAME` = 'my_table'Code: Select all
SHOW COLUMNS FROM `my_table`