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
Multiple select box population
Collapse
X
-
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
-
This is from the link I posted earlier: It assumes you've already made a mysql connection.
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.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>Comment
-
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 ???? areComment
-
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
-
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
-
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
Comment