Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

dynamically building selection list....

Status
Not open for further replies.

huskers

Programmer
Jan 29, 2002
75
0
0
US
I am new to php and I am trying to write a database management tool in php. The database i am using is Mysql. I am planning to have 3 selection lists. The first selection list displays all the databases in MySQL database. When any one database is selected the 2nd selection list displays all the tables in the selected database. When a table is selected the 3rd selection list displays all the columns in the table.

Can anyone tell me how I can build the selection lists dynamically in php.
 
1. Query MySQL 'SHOW DATABASES'
2. print out HTML with each db name in <option> tag within a <select> tag
3. If submitted and db name is present follow step 1 and 2 for SHOW tables for the named db
4. If submitted and table name is selected repeat step 1 and 2 for the columns.

Need more specific help? Ask.
 
Thanks for the response. I am looking more specifically at how to build a dynamic selection list to show all the tables in database when a particular database is selected. I do not know how to do this. How do i know that a particular database is selected.
 
PHP is server side. That means you have to send that information to the server.
Sometimes people are mistaken about how PHP works and think there is some kind of persistent connection between the client and server, but there ain't.
You need to tell the server what was selected by e.g. posting a form. The <select name="dbName"> element will transmit the selected option. That option is available through the $_POST array as $_POST['dbName'].
Your code then has to use that information to construct and execute the next query to get the table names.
You can post with a SUBMIT button or using some client side event handler (JavaScript) e.g. onChange.
More complicated than you thought, eh?
 
Thx. Do you happen to have any examples.
 
huskers -

I feel obliged to point out that there is already free software written to do just what you are looking for. Check out phpMyAdmin

Robert Carpenter
"You and I have need of the strongest spell that can be found to wake us from the evil enchantment of worldliness." - C.S. Lewis (The Weight of Glory)

robert (at) robertcarpenter (dot) net
 
There are several threads in this forum that present answers to your problem. Just go ahead and make use of the search function. There are numerous example code sections.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top