473,385 Members | 1,342 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

dynamic populated dropdown from mysql database

hi,
i m newbie php+mysql. in i have the following problem. i tried my best to solve it but could do it. please help me.

i have a from where 3 fields are STATE, AREA and SUBRUB. AREA is connected with STATE and SUBRUB is connected with AREA. when a person will select a STATE the corresponding AREA will be available in dropdown box. and when a AREA is selected the corresponding SUBRUB will be available in a dropdown box. please help me with the solution.

best regards,
Mainul
Sep 15 '09 #1
4 2791
TheServant
1,168 Expert 1GB
I am guessing that you are not submitting the form between changing STATE, AREA and SUBURB... if you are, you shouldn't.

That is a javascript/AJAX task, as once the page is on your screen, PHP is finished. Look here or just search in Google for the difference between Client side and Server side.
Sep 15 '09 #2
prabirchoudhury
162 100+
ok here is the sudo code

1.
Expand|Select|Wrap|Line Numbers
  1. $query1=mysql_query("SELECT DISTINCT AREA ,AREA _id FROM AREA  where STATE_ID = $ID");
  2.  
  3.  
  4.   dropdown1 <select name=dd1> <option value=''>Select Area</option>
  5.     <?php
  6.  
  7.       while($row1= mysql_fetch_array($query1)) {
  8.        echo "<option value='$row1[AREA _id]'>$row1[AREA]</option>";
  9.  
  10.       $query2=mysql_query("SELECT DISTINCT SUBRUB,SUBRUB_id FROM SUBRUB where SUBRUB_id = $row1[[AREA _id]");
  11.  
  12.       // dropdown 2
  13.      echo "<select name=dd2> <option value=''> select SUBRUB ..</option>";
  14.     while($row2= mysql_fetch_array($query2)) {
  15.        echo "<option value='$row2[SUBRUB_id]'>$row1[SUBRUB]</option>";
  16.  
  17.     } // end of second while
  18.  
  19.    echo </select>
  20.  
  21.    }  // end of first while
  22.  
  23. echo "<select>"
  24.  
could have a look on here
basic tutorial

:))
Sep 16 '09 #3
TheServant
1,168 Expert 1GB
prabirchoudhury, that will only display a static dropdown list? Unless I have missed something. But mainul05, if you combine prabirchoudhury's script with a little javascript or AJAX, and you will have your solution.
Sep 16 '09 #4
prabirchoudhury
162 100+
Y you are right
that javascript part he should get the tutorial link i have added. TheServant ,thanks for your mention.

:))
Sep 16 '09 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Harry Simpson | last post by:
Basically have a datalist now with an itemtemplate containing a textbox for user entry and a label. The datalist is bound to a database table. My boss wants the database table to have possible...
1
by: russ | last post by:
Hi all, Here's a problem I'm having with a dynamic table. Following the guidelines here (http://www.codeproject.com/aspnet/dynamiccontrols.asp), which make perfect sense. The problem is that...
7
by: Jeff Uchtman | last post by:
I know I have done this but my mind is fried. I have a dynamic dropdown in a form. I need to pull both the dynamic dropdown's ID and name listed in the dropdown. Need a little help with grey...
2
by: assgar | last post by:
Hi Developemnt on win2003 server. Final server will be linux Apache,Mysql and PHP is being used. I use 2 scripts(form and process). The form displays multiple dynamic rows with chechboxs,...
9
by: Tarscher | last post by:
hi all, I have this seemingly simple problem. I have lost a lot of time on it though. When a user selects a value from a dropdownlist (static control) a dynamic control is generated. I have...
4
by: Panna | last post by:
Hey there I am using phpMyAdmin and MySQL to develop a dbase application. I have a dropdown menu on one of the pages which gets populated automatically with data from a table in the database....
3
by: d1156676 | last post by:
Hi I have a Dynamic dropdown reading in data from a MySql database, I need to refresh the dropdown when the database is updated without refreshing the whole page. I have had a go at trying to...
0
by: pansell | last post by:
Hi, I have a dropdown list that is populated with table names from my database using SqlDataSource1. When I change the selected index I can get the table name back from the dropdown and display...
4
by: d0353101 | last post by:
Hi, I am having 2 dropdowns on my page. The values in both the drop downs have to be populated through DataBase. Problem : I dont know how to populate the second Dropdown automatically if...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.