Adam_Duski Posted January 14, 2014 Share Posted January 14, 2014 Hi , i have a database (dept_db) it contents of 3 tables (web , net , prog) , when i choose Dept like for example i makes Dept to (Web) so the (Web) group appears in the Students that get the inserted data from web table and display it in Students .and when i choose (Net) the Net group appears ,and when i don't choose any group ,i want it to disable the Students Select Tag which function must i use and where and how ! this is a example :http://www.redsn0w.us/2010/03/download-direct-links-jailbreak-guides.html Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/ Share on other sites More sharing options...
cyberRobot Posted January 14, 2014 Share Posted January 14, 2014 You could use JavaScript to populate the second dropdown based on the selection from the first. Perhaps you could find something here: https://www.google.com/search?q=javascript+populate+dropdown+based+on+another+dropdown Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465185 Share on other sites More sharing options...
jazzman1 Posted January 14, 2014 Share Posted January 14, 2014 Yeap, I agree with cyber using JS here. Take a look at my example. It's a little ugly but it would help to understand the logic. <html xmlns="http://www.w3.org/1999/xhtml"> <head> <script type="text/javascript"> // <![CDATA[ function changeFunc() { var count; var list1 = document.form1.Dept.options var list2 = document.form1.students for (count = 0; count < list1.length; count++) { if (list1[count].selected) { if (list1[count].value == '') { list2.disabled = true } else { list2.disabled = false } } } } // ]]> </script> <title>Drop-down list</title> </head> <body> <form action="" method="post" name="form1"> Dept: <select name="Dept" onchange="changeFunc();"> <option value="" selected>Select Dept....</option> <option value="1">Option #1</option> <option value="2">Option #2</option> <option value="2">Option #3</option> </select> Students: <select name="students" disabled="disabled"> <option value="1">Option #1</option> <option value="2">Option #2</option> <option value="2">Option #3</option> </select> </form> </body> </html> Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465196 Share on other sites More sharing options...
Adam_Duski Posted January 14, 2014 Author Share Posted January 14, 2014 Thanks for both of you jazzman1 it's great now ,, but when i choose option #1 from Dept i want to getting data from the table that i selected and when i choose option #2 from Depti want to getting data from another table and option #3 too ! Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465224 Share on other sites More sharing options...
jazzman1 Posted January 14, 2014 Share Posted January 14, 2014 (edited) This is only an example how to enable/disable the second dropdown list based on selected options of first one. Edited January 14, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465227 Share on other sites More sharing options...
Adam_Duski Posted January 14, 2014 Author Share Posted January 14, 2014 So , you don't know how can i get data from database to select tag ? Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465241 Share on other sites More sharing options...
jazzman1 Posted January 14, 2014 Share Posted January 14, 2014 (edited) Get the data from mysql and fill up the options/values to the first drop-down list, then use Ajax and javascript onselect event to populate the data to the second one based on your query to database. Do you know what Ajax does? Edited January 14, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465244 Share on other sites More sharing options...
Adam_Duski Posted January 14, 2014 Author Share Posted January 14, 2014 i don't know about ajax !can u help me ? Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465252 Share on other sites More sharing options...
jazzman1 Posted January 14, 2014 Share Posted January 14, 2014 (edited) http://www.xul.fr/en-xml-ajax.html ops....this is with php - http://www.xul.fr/ajax/ajax-php.php Edited January 14, 2014 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465254 Share on other sites More sharing options...
Adam_Duski Posted January 14, 2014 Author Share Posted January 14, 2014 I have failed until now i can't understand how to get data from table to the select tag I'm not good at programming Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465277 Share on other sites More sharing options...
jazzman1 Posted January 14, 2014 Share Posted January 14, 2014 I moved your thread to the Ajax section. What have you tried so far? Show us the code. Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465281 Share on other sites More sharing options...
Adam_Duski Posted January 14, 2014 Author Share Posted January 14, 2014 i have the code that u post it and i didn't change anything on it , now, i want to call the data from tables in my database for e.x : when i choose the option #1 bring me the data from table (web) and showing all data in that table in the student tag and when i choose the option #2 bring me the data from table (net) and showing all data in that table in the student tag and when i choose the option #3 bring me the data from table (prog) and showing all data in that table in the student tag that's all i want ! Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465285 Share on other sites More sharing options...
mac_gyver Posted January 14, 2014 Share Posted January 14, 2014 (edited) repeatedly just stating what you want your code to do and then expecting someone to post code that does that is not how programming help works. if you don't know how to do something in programming, you research it, for as much time as necessary, until you do understand it, because we cannot provide you with an understanding remotely over the Internet. programming help forums are for when you get stuck at a step with code you have written. you have to bring enough of the basics with you so that you can attempt and at least get the gist of what is being posted in the replies. you appear to not know how to make a form, with a select/drop-down menu, then take the submitted value from that form, query for data dependent on the value, and produce a related select/drop-down menu. you would need to start with the tasks that accomplish these goals. start by making your first select menu, submitting that menu (you can use an onchange event to submit the form without needing a specific submit button), test for that form submission in the php code, validate the value, then use the value to retrieve the data needed for the second select menu. get at least to this point so that you will be comfortable with the basic skills needed to perform this for any number of related select menus. btw - you would not store the data in three separate tables. you would have one table with a type or category column that relates the three choices web , net , prog with the corresponding students (in a students or user table.) Edited January 14, 2014 by mac_gyver Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465296 Share on other sites More sharing options...
JIXO Posted January 14, 2014 Share Posted January 14, 2014 Here, why don't you start with this. At first, change the dropdown items to display your database tables, after that change AJAX respond to display your table. Post any errors/problems you have so we can help u. Quote Link to comment https://forums.phpfreaks.com/topic/285353-getting-data-from-table-to-select-tag/#findComment-1465297 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.