User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the PHP section within the Web Development category of DaniWeb, a massive community of 423,949 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 4,214 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our PHP advertiser: Lunarpages PHP Web Hosting
Views: 4515 | Replies: 4
Reply
Join Date: Feb 2007
Posts: 4
Reputation: sunilpro is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sunilpro sunilpro is offline Offline
Newbie Poster

Help php script for dropdown to fetch DB list and then Tables

  #1  
Feb 4th, 2007
Dear members, I am new for Php, wish to develope two dropdown list. One listing all DB's availabe with MySQL and on selection of one DB second should list tables in that DB ( with no 'GO' type button). Once Table selected third dropdown will list fileds availabe,
Can some one help me.
Thanks in advance.
Sunilpro
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 135
Reputation: Rhyan is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Junior Poster

Re: php script for dropdown to fetch DB list and then Tables

  #2  
Feb 12th, 2007
Originally Posted by sunilpro View Post
Dear members, I am new for Php, wish to develope two dropdown list. One listing all DB's availabe with MySQL and on selection of one DB second should list tables in that DB ( with no 'GO' type button). Once Table selected third dropdown will list fileds availabe,
Can some one help me.
Thanks in advance.
Sunilpro


It can be done, however are you sure you want to be exposed like this. If you do this - it means you have hacked yourself and showed it to people.

Read carefully articles about security!
1. Access to all databases should have only root account! To make the thing you want you should log in from php as root! This is not secure at all!
2. If you want to make this, you should create a user granted view only. AND AVOID GIVING VIEW PERMISSIONS TO MYSQL_USER tables and DBS
3. The "no go" button change can be done with javascript, not with PHP. PHP can only insert the script where you need it. Look for onChange actions in some javascript reference.

If you still want to do this...well, we might guide you!

Good luck
Reply With Quote  
Join Date: Feb 2007
Posts: 4
Reputation: sunilpro is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sunilpro sunilpro is offline Offline
Newbie Poster

Re: php script for dropdown to fetch DB list and then Tables

  #3  
Feb 15th, 2007
Thanks a lot
I am writing a small offline apps to convert some data of multiple tables into one table with some middle processing and changes hence no problem of EXPOSURE so please guide me further.
Basically I am also new to JS Hence cannot undersatnd how to pass to and fro from PHP& JS.
Thanks for gre8 clue for onchange() event.
The specific prbolem with me is that I am stuck with >> How to choose SELECTED value (of listed database names) and pass on to the another dropdown which list the TABLES on SELECTED DB,
Thanks
Sunipro
Reply With Quote  
Join Date: Oct 2006
Location: Sofia, Bulgaria
Posts: 135
Reputation: Rhyan is an unknown quantity at this point 
Rep Power: 2
Solved Threads: 7
Rhyan's Avatar
Rhyan Rhyan is offline Offline
Junior Poster

Re: php script for dropdown to fetch DB list and then Tables

  #4  
Feb 16th, 2007
Originally Posted by sunilpro View Post
Thanks a lot
I am writing a small offline apps to convert some data of multiple tables into one table with some middle processing and changes hence no problem of EXPOSURE so please guide me further.
Basically I am also new to JS Hence cannot undersatnd how to pass to and fro from PHP& JS.
Thanks for gre8 clue for onchange() event.
The specific prbolem with me is that I am stuck with >> How to choose SELECTED value (of listed database names) and pass on to the another dropdown which list the TABLES on SELECTED DB,
Thanks
Sunipro


Ok, if you're new both to PHP and MySQL, it is a good thing to start from the reference manuals of both PHP and MySQL. If you are new to html a good way to start is for example W3Schools.com. I will outline how it is made, still you have to figure it out.

1. in order to access the DB with full privilege you should login as root. This means that PHP should post to MySQL root as user and rootpass as password to have all privileges.
2. If connection is successful, your mysql querry should be smth like this
[php]$query = mysql_query('show databases;');[/php]
This will show all databases available on the server.
3. The results you should load in a <SELECT> element as <OPTION>s. This is done using some loop as foreach, while or for...depends on your choice.

Note in order to submit the form without GO button, you should make it like this
[html]<SELECT name="dbselec" onchange="document.form.submit()">[/html]
For each option you should insert a value like this:
e.g. you have loaded your results from the querry into $result wich holds the databases.Option should look like this
[php]echo '<option value="'.$result.'">'.result.'</option>';[/php]

4. When selected, the value will be submitted to next php script, wich will make another query using one of the following methods.
A. [php]$selectDB=mysql_select_db($option.value.from.previous.page);[/php]
B. [php]$query=mysql_query('show tables;');[/php]


OR

[php]$query = mysql_query('show tables from '.$option.value.from.previous.page.';');[/php]

5. Load the results the same way you loaded the result from the first query.
6. Now, I don't get it clear - if you want to view the table content or view the table structure.
A to view the table structure folow the above instructions to make the query, however the query should be like this:
[php]$query=mysql_query('describe table.'$table_name_from_previoust_page'.;');[/php]

OR

B. To view all records, your query should be:

[php]$query = mysql_query('SELECT * FROM'.$table_name_from_previous_page.';');[/php]

That's all. You should learn yourself how to display the results on your page. If I give you the complete script as it should look like, you'll never learn a thing, so forgive me not giving you all ready-made.

Good luck with learning!
Reply With Quote  
Join Date: Feb 2007
Posts: 4
Reputation: sunilpro is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
sunilpro sunilpro is offline Offline
Newbie Poster

Re: php script for dropdown to fetch DB list and then Tables

  #5  
Feb 16th, 2007
Hi Rhyan,
Gre8 giudeline u gave. I am following. Thanks to Internet that connected two far freinds.
Please keep guiding if I find any difficulty.
Thanks for your time.
sunilpro
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb PHP Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the PHP Forum

All times are GMT -4. The time now is 6:13 am.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC