for loop - PHP set multi select dropdown -


I am dragging data from my database to retrieve several options for a multi-select drop down. I am trying to reset those values ​​as selected to them, but only one of them is selected.

My array from the database:

  [data] = & gt; Simple expression object ([term] => LTA [prevention] => simple assemble object ([cause] => hey ([0] = & gt; simple assemment object ([process] = & gt; Recruitment [processID] = & gt; 4) [1] = & gt; Simple Explicit Object ([Process] = & gt; Payment Management [Processed] => 3] [2] => Simple Assemblement Object ( [Procedure] = & gt; Not applicable [processID] = & gt; 2))))   

Here's the HTML / PHP I'm using to generate options and the array Trying to re-select the options:

  & lt; Select name = "prevention" id = "prevention" class = "form-control dd ff" placeholder = "select 1 or more options" multiple = "multiple" & gt; & Lt ;? Php foreach ($ process-> data as $ process) {foreach ($ recordDetails-> data-> prevention-> cause is $ as $) {if ((int) $ is - & gt; processID = = (Int) $ process- & gt; processID) {$ isSel = 'selected'; } And {$ isSel = ''; }}? & Gt; & Lt; Option value = "& lt ;? php echo $ process- & gt; Process ID. '' '$ Iscel' & gt;;? & Gt; & lt; php resonance $ process- & gt; process;? & Gt; & lt; / option & gt; & lt ;? php}? & Gt; & lt; / select & gt; You are overwriting  $ isSel  in internal lip,   

Instead of variables Has been started outside the inner loop:

  select name = "prevention" id = "prevention" class = "for M-Control DD FF "Placeholder =" Select 1 or more options "Multiple =" Multiple "& gt; & gt; Php foreach ($ process-> Data as $ process); $ isSel = ''; Foreach ($ recordDetails-> data-> prevention-> causes $ is $): if ((int) $ is-> processID == (int) $ process-> processID) {$ IsSel = 'is selected'; breakdown;} endorph;? & Gt; & lt; option value = "& lt ;? Php echo $ process-> Process ID '' '$ Hasel' '& gt;'; ? & Gt; & Lt ;? Php resonation process $ & gt; process; ? & Gt; & Lt; / Options & gt; & Lt ;? php endforeach; ? & Gt; & Lt; / Select & gt;    

Comments

Popular posts from this blog

php - PDO bindParam() fatal error -

logging - How can I log both the Request.InputStream and Response.OutputStream traffic in my ASP.NET MVC3 Application for specific Actions? -

java - Why my included JSP file won't get processed correctly? -