Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>Well, I can see a couple of problems.</p> <p>First, that array_walk on line 2 isn't doing anything as it's running on an empty... array? string? which is then clobbered. You should be walking along the $_POST element and then imploding what results.</p> <p>Second, if somebody checks that box for "other" you're going to get an extra empty entry in pVital, which is a much more awkward way of figuring out that box has been checked than giving it its own distinct name.</p> <p>Third, you're collapsing a bunch of discrete values into a single text field and then expecting to be able to unpack the text field -- maybe by exploding it along the commas? -- and get the discrete values back, which is problematic. </p> <p>If you actually control the database I'd suggest making a table after the pattern</p> <pre><code>admission_vital_signs( admission_order_id INT, vital_sign_text VARCHAR, is_free_text BOOL) </code></pre> <p>to hold said discrete values.</p> <p>If you don't control the database but do control the output mechanism I'd suggest using a delimiter that doesn't appear in nature -- the pipe "|" is usually good for this -- so you can at least split things cleanly, and maybe preface any freetext with FREETEXT:: ("::" is also generally not found in nature) so you can recognize it when it shows up.</p> <p>If you don't control the database or the output mechanism you need to edit your original post with what the output mechanism is that you have to work with.</p> <p>EDITED:</p> <p>Alright, if I understand correctly, you're retrieving this data from the database and trying to work out from it whether you should tick the appropriate boxes on postback, so you do control the output mechanism. The following set of instructions assume you don't control the database; if you do, making a new table is the way to go here but the method's still crib-worthy.</p> <p>Name the checkbox by other "pVitalOther', value '1', and the textfield 'pVitalOtherText'. No brackets. Here's some psuedocode for going in and coming out.</p> <pre><code>if isset($_POST['pVitalOther']) $_POST['pVital'][] = "FREETEXT::{$_POST['pVitalOtherText']}"; $pvitals = implode('|', array_walk('MySQLEscape', $_POST['pVital'])); //and store $pvitals in the database </code></pre> <p>When you're coming back out:</p> <pre><code>$pvitals = explode('|', $row['VitalSigns']); $pvitals_last = $pvitals[count($pvitals)-1]; if strstr("FREETEXT", $pvitals_last) $lastparts = explode('::', $pvitals_last); $pvitalOther = true; $pvitalOtherText = $lastparts[1]; </code></pre> <p>Then when you go to build the checkboxes pipe in a bit of PHP about like</p> <pre><code>&lt;? php if (in_array('Daily Weight', $pVital)) echo "checked"; ?&gt; </code></pre> <p>right into the middle of those fixed-value checkbox tags. Do the same thing for your "other" based on pVitalOther and set the appropriate initial visibility and value of the freetext input field.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload