Jump to content

getting data from table to Select Tag !


Adam_Duski

Recommended Posts

Hi , 

 

i have a database (dept_db) it contents of 3 tables (web , net , prog) ,

 

634185979.png

 

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

 

322886643.png

 

 

Link to comment
Share on other sites

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>
Link to comment
Share on other sites

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 by jazzman1
Link to comment
Share on other sites

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 ! 

Link to comment
Share on other sites

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 by mac_gyver
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.