Jump to content

Undetermined number of data items, what is best method of input?


Guest kilbad

Recommended Posts

I have a type of data (medication names) that I want a user to input into a form, and then have those medications listed in a MySQL db in separate columns for each particular patient; so one row would look like:

 

Patient's Chart Number | first medication | second medication | third medication | and so forth..

 

My question is this: What is the best way, using PHP and/or javascript to have a user input multiple medications in a form when there is a different/undetermined number of medications that will need to be entered for each patient.  I don't want to have a form with a absolute number of text input fields because what if there are more medication than fields?  I also do not what to delimit the data in a single input field with spaces, commas, etc, because each medication will also have additional input fields that will need to be filled out (frequency, dosage).

 

Any ideas?  I just want to make sure I am smart about the way I do this.

 

Let me know if you need any clarification on what I have written.  Thank you all so much in advance!

 

Brendan

I am sure there is a Javascript/AJAX solution out there that will make a new text field appear as soon as a one is filled in. Sadly, I'm not the person to ask about that.

 

In terms of the back-end, one possible solution is to store all the medication names in one field using commas, or any other character to seperate them. From there you can just use explode to break them up into separate array values

 

<?php
//Query returns something along the lines of $results = "Medication1|Medication2|Medication3";
$medcations = explode("|", $results);
print_r($medications);
?>

 

There might be a more practical solution.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.