472,374 Members | 1,267 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,374 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 5128
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.

Nov 16 '08 #2
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
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.

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
1,584 Expert 1GB
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.

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.

Nov 26 '08 #8
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
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
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
1,584 Expert 1GB
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>
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!

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
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
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
1,584 Expert 1GB
This is from the link I posted earlier: It assumes you've already made a mysql connection.

Expand|Select|Wrap|Line Numbers
  2. <select name="symptomID">
  3. <?php
  4. $sql = "SELECT id, name FROM symptom".
  5. "ORDER BY name";
  7. $rs = mysql_query($sql);
  9. while($row = mysql_fetch_array($rs))
  10. {
  11.   echo "<option value=\"".$row['id']."\">".$row['name']."</option>\n  ";
  12. }
  13. ?>
  14. </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.
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
  3. //loads the configuration file
  4. require_once('inc/config.php');
  6.   $sql="INSERT INTO disease_has_symptom (disease_id, symptom_id) VALUES (??????)";
  8.   if (!mysql_query($sql,$con))
  9.   {
  10.   die('Error: ' . mysql_error());
  11.   }
  13. mysql_close($con)
  14. ?>

How shall i fetch the ids of the selected stuff to put where the ???? are
Nov 26 '08 #19
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
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
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

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...
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...
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...
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...
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,...
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...
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...
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...
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...
by: Kemmylinns12 | last post by:
Blockchain technology has emerged as a transformative force in the business world, offering unprecedented opportunities for innovation and efficiency. While initially associated with cryptocurrencies...
by: Naresh1 | last post by:
What is WebLogic Admin Training? WebLogic Admin Training is a specialized program designed to equip individuals with the skills and knowledge required to effectively administer and manage Oracle...
by: antdb | last post by:
Ⅰ. Advantage of AntDB: hyper-convergence + streaming processing engine In the overall architecture, a new "hyper-convergence" concept was proposed, which integrated multiple engines and...
by: Oralloy | last post by:
Hello Folks, I am trying to hook up a CPU which I designed using SystemC to I/O pins on an FPGA. My problem (spelled failure) is with the synthesis of my design into a bitstream, not the C++...
by: Carina712 | last post by:
Setting background colors for Excel documents can help to improve the visual appeal of the document and make it easier to read and understand. Background colors can be used to highlight important...
by: BLUEPANDA | last post by:
At BluePanda Dev, we're passionate about building high-quality software and sharing our knowledge with the community. That's why we've created a SaaS starter kit that's not only easy to use but also...
by: Johno34 | last post by:
I have this click event on my form. It speaks to a Datasheet Subform Private Sub Command260_Click() Dim r As DAO.Recordset Set r = Form_frmABCD.Form.RecordsetClone r.MoveFirst Do If...
by: jack2019x | last post by:
hello, Is there code or static lib for hook swapchain present? I wanna hook dxgi swapchain present for dx11 and dx9.
by: F22F35 | last post by:
I am a newbie to Access (most programming for that matter). I need help in creating an Access database that keeps the history of each user in a database. For example, a user might have lesson 1 sent...

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.