Multiple select box population

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • toshibata
    New Member
    • Nov 2008
    • 10

    Multiple select box population

    So i have this portion of code

    Code:
    <form method="post" action="insert_disease_has_symptom_db.php" onsubmit="multipleSelectOnSubmit()">
    <select multiple name="fromBox[]" id="fromBox">
    	<option value="1">Sintoma 1</option>
        <option value="2">Sintoma 2</option>
    	<option value="3">Sintoma 3</option>
    	<option value="4">Sintoma 4</option>
    	<option value="5">Sintoma 5</option>
    	<option value="6">Sintoma 6</option>
        <option value="7">Sintoma 7</option>
        <option value="8">Sintoma 8</option>
    </select>
    <select multiple name="toBox[]" id="toBox">
    </select>
    <input type="submit" value="OK">
    I am to populate my option values with names on a table in a sql, storing afterwards the ids of the selected names that i passed to the right. Any ideas, because im stuck :\
    Last edited by Markus; Nov 16 '08, 01:02 PM. Reason: added # tags
  • Markus
    Recognized Expert Expert
    • Jun 2007
    • 6092

    #2
    I don't understand. Can you explain a little more?

    Also, you'll notice I've formatted you code. Please, when posting code, wrap it in [code] tags. Just higlight the code, and hit the '#' button at the top of this editor.

    Moderator.

    Comment

    • pbmods
      Recognized Expert Expert
      • Apr 2007
      • 5821

      #3
      Heya, toshibata.

      Try print_r()'ing $_POST after you submit the form, and you'll see what data has been input.

      Comment

      • toshibata
        New Member
        • Nov 2008
        • 10

        #4
        Im trying to populate those option values with info stored on my database, but since this is the first time im doing a multiple select box where you have to select from the left box (which will contain all attributes) the attributes you which tou chose passing to the right box.

        After Submiting it should store on a different table the id of the attributes i selected.

        Managed to get this working on a scroll down type thing, but that only allows me to chose one attribute at a time, so im stuck :\

        Any help would be most appreciated

        Comment

        • dlite922
          Recognized Expert Top Contributor
          • Dec 2007
          • 1586

          #5
          I'm still a little lost.

          Explain it more in the means of the application, what is this page support to help the user do.

          From the what it looks like you're trying to have the user select one (or more) symptoms from the first drop down or multi-select box, based on their choices you want to display the diseases that cause these symptom and have the user select one (or more?) of these diseases or illnesses?

          Let me know if this is what you want to do.




          Dan

          Comment

          • toshibata
            New Member
            • Nov 2008
            • 10

            #6
            No, i wish to populate with symptoms which are on my database, selecting the ones that are on that specific disease, saving after that the ID of those symptoms in the database.

            Hope i made myself clear

            Comment

            • dlite922
              Recognized Expert Top Contributor
              • Dec 2007
              • 1586

              #7
              Originally posted by toshibata
              No, i wish to populate with symptoms which are on my database, selecting the ones that are on that specific disease, saving after that the ID of those symptoms in the database.

              Hope i made myself clear
              Well, that was assumed. I'm not actually asking you to have the symptom box hard-coded, it would be pulled from the database (list of all symptoms).

              I don't know what you mean by "saving after that the ID of those symptoms in the database." It's not a complete sentence.

              Is this for a doctor that assigns the symptoms to a disease or for visitors who wish to find out with disease is causing their symptom by indicating those symptoms on the site?

              Also: I've seen a similar application on web MD. The list of symptoms are too large for a single drop down. They at least need to be categorized.

              Here's an example at WebMD:

              Symptom Checker

              I'm trying to find out what your trying to do so I can help you achieve it.


              Dan

              Comment

              • toshibata
                New Member
                • Nov 2008
                • 10

                #8
                Ill try to explain in more detail and as well as i can.

                I have a database for a clinic. And the objective is to make mini-appications in PHP to insert data. One of those insertions ( The one im having problems with ) is to insert diseases, making a form asking for its details, inserting it after in the database. After that disease has been inserted, i have to use a multiple select box in which on the left part will be all the symptoms i have stored on the symptoms table on my database. From which ill choose the symptons present on the disease i inserted into the database on the previous step, moving them to the right box and clickling submit. This will then store in a table name disease_has_sym ptom a tuple of the id of the disease and the symptom.

                Tried to be as clear as possible, hope you understand the issue as this is burning my brain :>

                Might aswell post an image of the tables of the database maybe will make my point more clear.

                Last edited by Markus; Nov 26 '08, 11:03 AM. Reason: changed [img] to [url] to prevent it widening the screen.

                Comment

                • dps225
                  New Member
                  • Nov 2008
                  • 7

                  #9
                  I don't see, given the code provided, how users move the selected symptoms from the complete list (fromBox[]) to the short list on the right (toBox[]). If, on submit, nothing has been added to the toBox (and subsequently selected), then on the post your toBox[] field will be empty.

                  Presumably you could do this with just the one multiple select box, so perhaps it's a matter of design/taste to use the "all available -> selected" model. If you have just the one fromBox, the selected items should come through on the POST and you'll have your list.

                  If you do want the two boxes, you probably need either some drag and drop functionality, or at least a button to move items from the left to the right (and back again) and then, before submitting, make sure to select all the items in the right box, because just having the options won't help unless they're selected.

                  Of course, maybe you did all that and just didn't put it in your code sample. In which case I probably didn't help with the brain burning thing.

                  Comment

                  • dlite922
                    Recognized Expert Top Contributor
                    • Dec 2007
                    • 1586

                    #10
                    Ok here's what I understand. You need to give the user a way to add a disease to the disease table and then have them select the symptoms (from the list you already have in the database) that apply to that disease. Then you save this link in the table you specified. the relationship of the disease and symptom table is a many to many relationship, ie. one or more disease match up to one or more symptoms, obviously.

                    here's what I would do. You don't need to give the user two pages. It can all be done in one. Give the user the form fields for the name of the disease, its description, etc and right below it, display a multi-select box with all your symptoms where they can select multiple symptoms. Once they hit submit, You'll grab the data, create the disease (after appropriate validations) and insert it into the database. Once you insert it, you can call the mysql_insert_id () and be presented with ID (or primary key value) of that disease.

                    You then create an entry in the disease_has_sym ptom table by inserting all the symptoms that disease has. (I'm assuming the multi-select box above will have the symptom ID (primary key) as the value, and the name as the label.

                    Here's how you populate the symptom mult-select box:
                    Populate Select Box - PHP and MySQL | Tech-Evangelist

                    Let's go back to your original question. Which part of this page you don't know how to do?

                    Comment

                    • toshibata
                      New Member
                      • Nov 2008
                      • 10

                      #11
                      The problem is i might have to select multiple symptoms, thats why i was going through the 2 boxs route, passing the ones associated to that disease to the right and then saving to database.That code only allows me to get 1

                      Comment

                      • dps225
                        New Member
                        • Nov 2008
                        • 7

                        #12
                        The only thing you should have to add to the Tech-Evangelist example would be the "multiple" designation in the select tag - then you would be able to select more than one from that form element.

                        Comment

                        • dlite922
                          Recognized Expert Top Contributor
                          • Dec 2007
                          • 1586

                          #13
                          Originally posted by toshibata
                          The problem is i might have to select multiple symptoms, thats why i was going through the 2 boxs route, passing the ones associated to that disease to the right and then saving to database.That code only allows me to get 1
                          oh no, that's now true. Here's the code to make a select box that gives you an array of those selected when you grab it with $_POST()

                          Code:
                          <select name="symptoms[]" multiple="multiple" size="5">
                          <option value="1">Pain</option>
                          <option value="2">Ache</option>
                          <option value="3">Rash</option>
                          <option value="4">Cough</option>
                          <option value="5">Ache</option>
                          <option value="6">Rash</option>
                          <option value="7">Cough</option>
                          </select>
                          notice the name has [] attached to it (symptoms[])

                          You can do this if you have multiple form elements with the same name and you want to grab them on the PHP side as an array. Remeber however, when you do your $_POST['symptoms'], you don't need to add the brackets to the name.

                          An example with code: PHP Tutorial-Multi-Select

                          Good luck!


                          Dan

                          Comment

                          • toshibata
                            New Member
                            • Nov 2008
                            • 10

                            #14
                            Still cant see how i would replace those Rash, etc you write there with my own stuff from the database :\

                            Comment

                            • dps225
                              New Member
                              • Nov 2008
                              • 7

                              #15
                              Well, let's back up a second... Your original code has a complete multiple-select box named fromBox[]. I don't think that's the problem. The problem seems to be that you have another multi-select box (toBox[]) where you are expecting to see the results, but you have no way of moving symptoms from the fromBox[] to the toBox[]. When you submit that form nothing will ever be in the toBox[].

                              Comment

                              Working...