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

Member Avatar for Rhyan

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

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

Member Avatar for Rhyan

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

$query = mysql_query('show databases;');

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

<SELECT name="dbselec" onchange="document.form.submit()">

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

echo '<option value="'.$result.'">'.result.'</option>';

4. When selected, the value will be submitted to next php script, wich will make another query using one of the following methods.
A.

$selectDB=mysql_select_db($option.value.from.previous.page);

B.

$query=mysql_query('show tables;');

OR

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

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:

$query=mysql_query('describe table.'$table_name_from_previoust_page'.;');

OR

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

$query = mysql_query('SELECT * FROM'.$table_name_from_previous_page.';');

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!

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

Hi guys i m facing a problem with drop down box the condition is i have some entries in my database like some country names & i m executing a query to findout user's selected country from that DB so now i want to show all country names in a single drop down with that particular user's selected country is show "SELECTED"

Member Avatar for Rhyan

Well...this means you should check for a present value in an array. Let me explain it like that:
1. You have the country array - eg. $countries.
2. You have your user country value - eg. $user_country = 'US'

I prefer the 'for' loop so I will put it that way.

$countrykeys = count($countries);

print (<select>);
for ($i=0;$i<$countrykeys;$i++)
{
if ($country[$i]==$user_country)
{
print (<option selected='selected'>$country[$i]</option>);
}
else
{
print(<option>$country[$i]</option>);
}
}
print (</select>);

This is a sketch of the code you should use. Of course you can do it in any other manner you like, and for sure you have to update it with your values. But if you get the idea you'll fix it quite fast

Good luck

HI,

THNX FOR HELPING IN MY LAST POST.

Now i wants the help in follwing problems.


i have a table in my sql named as "retailer001". i have a php page that have the
data entry form of all field that are in mysql table.

my table retailer001 having 11 fields (S No, Outlet ID,Date, Time ....... so on)
S No column has auto increment value and also primary key.
i have the php page which have the data entry form of 10 text field without the S NO
because the S No having auto increment and Null value.
In php data entry form i manually enter the date and time. i want help in that process. can any one
help me how can i enter the date and time in date and time column from system time automatically.

in clear words i want that i can't enter the date and time in data entry form. i want date
and time automatically insert into date and time column when i save or insert the remainings data.

please please please
please help me

Member Avatar for Rhyan

Depends on how did you format your column in the SQL table.
If you have defined the column as a varchar() then you can format the date and time in whatever way you like using the php date() function
http://php.net/manual/en/function.date.php

If you have defined the SQL table column to be of type datetime() then you have to consult the SQL manual for the correct date formatting and then use the PHP to submit time and date in the correct way.

If I am not mistaking, there is option in sql to define a column as timestamp(), so it will enter time and date of the creation of the record, so php has nothing to do with it. Check the sql manual first.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.