Multiple select box population

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

    #16
    No no, i have full code with all the buttons to pass info from left to right. The problem is the populating the left one with the symptoms on my database

    Comment

    • dps225
      New Member
      • Nov 2008
      • 7

      #17
      Ah, well then the code from the Tech-evangelist article posted by dlite a few posts ago should do the trick. The HTML structure of your "fromBox[]" is sound, you just need to query the database and, rather than writing out all the option tags, loop over the query results (something like "select * from symptoms") to create an option tag for each symptom with the appropriate id and value.

      Comment

      • dlite922
        Recognized Expert Top Contributor
        • Dec 2007
        • 1586

        #18
        Originally posted by toshibata
        No no, i have full code with all the buttons to pass info from left to right. The problem is the populating the left one with the symptoms on my database
        This is from the link I posted earlier: It assumes you've already made a mysql connection.

        Code:
        <select name="symptomID">
        <?php
        $sql = "SELECT id, name FROM symptom".
        "ORDER BY name";
        
        $rs = mysql_query($sql);
        
        while($row = mysql_fetch_array($rs))
        {
          echo "<option value=\"".$row['id']."\">".$row['name']."</option>\n  ";
        }
        ?>
        </select>
        Although if you know PHP well, you wouldn't do it this way. I would use scripts in advance that get the data, perhaps a framework, and maybe even a templating system like Smarty that will generate the options for me without doing a loop.

        Comment

        • toshibata
          New Member
          • Nov 2008
          • 10

          #19
          it worked finally, many thanks dude

          Although i know have a new problem which is, its suppose to save the id of the disease and symptom on the disease_has_sym ptom php.

          Code:
          <?php
          
          //loads the configuration file
          require_once('inc/config.php');
          
            $sql="INSERT INTO disease_has_symptom (disease_id, symptom_id) VALUES (??????)";
          
            if (!mysql_query($sql,$con))
            {
            die('Error: ' . mysql_error());
            }
          
          mysql_close($con)
          ?>

          How shall i fetch the ids of the selected stuff to put where the ???? are

          Comment

          • dps225
            New Member
            • Nov 2008
            • 7

            #20
            Both the disease ID and symptom IDs should be POSTed from the form on the previous page. The diseaseID would likely have been in a hidden field having been created on the first page. The symptomIDs should be the values of your multiple select toBox[] field. You will need to insert a separate set of values for each symptom ID (though the disease ID should always be the same).

            Comment

            • toshibata
              New Member
              • Nov 2008
              • 10

              #21
              Im not being able to get the id from disease, should i put disease page on the same page as the multiple select box for symptoms of that disease to be able to get the id ?

              Comment

              • dps225
                New Member
                • Nov 2008
                • 7

                #22
                From your description of the flow in post #8 in this thread, you have a first page where the user enters a name (and possibly other info) for a new disease to add to the database. When the user submits that form, you insert a new disease. When you do so, you should be sure to find out what ID was assigned to that new disease, then include this ID in the same form as the one used to identify the symptoms. You can use the PHP function mysql_insert_id () to get the ID immediately after your insert statement has executed.

                Someone earlier suggested combining these two pages into one and that is certainly possible. In fact, since the selection of symptoms is not dependent on any info entered for the new disease, you might save some page views/steps in this process by doing so. That's mostly a matter of usability and design... the steps you need to go through to get a new disease and its symptoms into a database are essentially the same either way.

                Comment

                • toshibata
                  New Member
                  • Nov 2008
                  • 10

                  #23
                  Thanks for all the suggestions,

                  Im having this issue when trying to insert the ids on table.

                  Error: Cannot add or update a child row: a foreign key constraint fails (`db/remedy_has_plan t`, CONSTRAINT `remedy_has_pla nt_ibfk_1` FOREIGN KEY (`remedy_id`) REFERENCES `remedy` (`remedy_id`) ON DELETE NO ACTION ON UPDATE NO ACTION)

                  Any ideas ?

                  Comment

                  • anijos
                    New Member
                    • Nov 2008
                    • 52

                    #24
                    It seems a foreign key constarint is violated. you are using a remedy_id which is not present in remedy table.

                    Comment

                    Working...