473,326 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

Multiple select box population

So i have this portion of code

Expand|Select|Wrap|Line Numbers
  1. <form method="post" action="insert_disease_has_symptom_db.php" onsubmit="multipleSelectOnSubmit()">
  2. <select multiple name="fromBox[]" id="fromBox">
  3.     <option value="1">Sintoma 1</option>
  4.     <option value="2">Sintoma 2</option>
  5.     <option value="3">Sintoma 3</option>
  6.     <option value="4">Sintoma 4</option>
  7.     <option value="5">Sintoma 5</option>
  8.     <option value="6">Sintoma 6</option>
  9.     <option value="7">Sintoma 7</option>
  10.     <option value="8">Sintoma 8</option>
  11. </select>
  12. <select multiple name="toBox[]" id="toBox">
  13. </select>
  14. <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 :\
Nov 16 '08 #1
23 5190
Markus
6,050 Expert 4TB
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.
Nov 16 '08 #2
pbmods
5,821 Expert 4TB
Heya, toshibata.

Try print_r()'ing $_POST after you submit the form, and you'll see what data has been input.
Nov 16 '08 #3
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
Nov 25 '08 #4
dlite922
1,584 Expert 1GB
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
Nov 25 '08 #5
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
Nov 26 '08 #6
dlite922
1,584 Expert 1GB
@toshibata
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
Nov 26 '08 #7
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_symptom 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.

http://img151.imageshack.us/img151/3992/naturalmc0.png
Nov 26 '08 #8
dps225
7
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.
Nov 26 '08 #9
dlite922
1,584 Expert 1GB
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_symptom 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?
Nov 26 '08 #10
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
Nov 26 '08 #11
dps225
7
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.
Nov 26 '08 #12
dlite922
1,584 Expert 1GB
@toshibata
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()

Expand|Select|Wrap|Line Numbers
  1. <select name="symptoms[]" multiple="multiple" size="5">
  2. <option value="1">Pain</option>
  3. <option value="2">Ache</option>
  4. <option value="3">Rash</option>
  5. <option value="4">Cough</option>
  6. <option value="5">Ache</option>
  7. <option value="6">Rash</option>
  8. <option value="7">Cough</option>
  9. </select>
  10.  
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
Nov 26 '08 #13
Still cant see how i would replace those Rash, etc you write there with my own stuff from the database :\
Nov 26 '08 #14
dps225
7
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[].
Nov 26 '08 #15
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
Nov 26 '08 #16
dps225
7
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.
Nov 26 '08 #17
dlite922
1,584 Expert 1GB
@toshibata
This is from the link I posted earlier: It assumes you've already made a mysql connection.

Expand|Select|Wrap|Line Numbers
  1.  
  2. <select name="symptomID">
  3. <?php
  4. $sql = "SELECT id, name FROM symptom".
  5. "ORDER BY name";
  6.  
  7. $rs = mysql_query($sql);
  8.  
  9. while($row = mysql_fetch_array($rs))
  10. {
  11.   echo "<option value=\"".$row['id']."\">".$row['name']."</option>\n  ";
  12. }
  13. ?>
  14. </select>
  15.  
  16.  
  17.  
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.
Nov 26 '08 #18
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_symptom php.

Expand|Select|Wrap|Line Numbers
  1. <?php
  2.  
  3. //loads the configuration file
  4. require_once('inc/config.php');
  5.  
  6.   $sql="INSERT INTO disease_has_symptom (disease_id, symptom_id) VALUES (??????)";
  7.  
  8.   if (!mysql_query($sql,$con))
  9.   {
  10.   die('Error: ' . mysql_error());
  11.   }
  12.  
  13. mysql_close($con)
  14. ?>

How shall i fetch the ids of the selected stuff to put where the ???? are
Nov 26 '08 #19
dps225
7
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).
Nov 26 '08 #20
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 ?
Nov 26 '08 #21
dps225
7
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.
Nov 26 '08 #22
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_plant`, CONSTRAINT `remedy_has_plant_ibfk_1` FOREIGN KEY (`remedy_id`) REFERENCES `remedy` (`remedy_id`) ON DELETE NO ACTION ON UPDATE NO ACTION)

Any ideas ?
Nov 28 '08 #23
anijos
52
It seems a foreign key constarint is violated. you are using a remedy_id which is not present in remedy table.
Nov 28 '08 #24

Sign in to post your reply or Sign up for a free account.

Similar topics

0
by: Megan | last post by:
Data Comparison: Sample Versus Rest of Population. I have a population of data, and I want to take a sample of that population and compare it against the entire population. I have a database...
2
by: Tarvos{k} | last post by:
Okay folks, I am back with another somewhat weird problem. I have a table that I am trying to run a query on that has the following fields: City, State, Zip Code, Population, Households. The...
1
by: Jeff Gardner | last post by:
Greetings: I have a table with 3 pieces of data that I would like to use to dynamically populate 3 drop downs using javascript. The fields are state, orgname, office. If it's not already...
14
by: neonman14 | last post by:
Hello I am in Intro to Java Programming and I am having problems with assignment. The Homework assignment is called Population. Population Write a program that will predict the size of a...
8
by: Supermansteel | last post by:
I have a query that counts how many results are in each branch out of 5000 rows. I am trying to condense even further and only show the Top 2 Branches in every State (so should reflect 100 results,...
6
by: Igor | last post by:
Hello I have the following problem. I have three drop down lists on my page. They are filled with data from a database. Initially only the first one is enabled. The next one is enebled when...
3
by: Andrew Meador | last post by:
I have searched and found where this has been discussed, but the suggestions I have found have all ended up tuning into debated about whether it needs to be done - but - as far as I can tell - I...
1
by: Clive Swan | last post by:
Hi I am trying to sum a population field that may have 140 records for each Ward (example). Any suggestions on the best way to do this. I would like to have a unique record for each Ward...
1
by: tg | last post by:
http://img522.imageshack.us/img522/8647/scan10005ci7.jpg As a percentage of world inhabitants, the white population will plummet to a single digit (9.76%) by 2060 from a high-water mark of...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.