iammudassir Posted November 30, 2012 Share Posted November 30, 2012 let suppose i have 3 fields in my form field 1 = Namefield 2 = Dept_code (may be it is a combo box or you sugest what i do)Field3= Dept_name i have a table in my mysql databse with 2 fields like this dept_code dept_name1 accounts2 finance3 administration now i starting filling up my form i enter abc in name field Qestion 1 i want my all dept code from database in my dept_code combo box field means 1 2 and 3 Question 2 when i select '1' from list i want "accounts" in field3 because dept_code 1 = accounts in database i know query will be like this select dept_name from table where dept_id = 1 i want very simple php coding to do this i am not expert Link to comment Share on other sites More sharing options...
JamesB Posted November 30, 2012 Share Posted November 30, 2012 Qestion 1 i want my all dept code from database in my dept_code combo box field means 1 2 and 3 echo '<select>';$result = mysqli_query( "select dept_code from table" );while ($row = mysqli_fetch_array($result)){echo '<option>'.$row['dept_code'].'</option>';}echo '</select>'; for question 2, if you want to use that query: select dept_name from table where dept_id = 1 you will need to use ajax to send a request to php, and have php reply with the single dept name. alternatively you could avoid ajax by sending all dept names to the client before the form is submitted. 1 Link to comment Share on other sites More sharing options...
iammudassir Posted November 30, 2012 Author Share Posted November 30, 2012 echo '<select>'; $result = mysqli_query( "select dept_code from table" ); while ($row = mysqli_fetch_array($result)) { echo '<option>'.$row['dept_code'].'</option>'; } echo '</select>'; for question 2, if you want to use that query: select dept_name from table where dept_id = 1 you will need to use ajax to send a request to php, and have php reply with the single dept name. alternatively you could avoid ajax by sending all dept names to the client before the form is submitted. Thankyou very much this is really is easy solution for me i will inform you after apply this Link to comment Share on other sites More sharing options...
iammudassir Posted November 30, 2012 Author Share Posted November 30, 2012 thank you jamesB i will reply you after apply this solution Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now