title: PHP Form Processing from Dimensional array
body: <p>I have the following function,  </p>
  
  <pre><code>&lt;pre&gt;
  public function getFree($cp) {
              global $glb_con;
  
              try {
                  $sql = "SELECT p.ID, w.ID, p.fname, p.lname, w.desc FROM weight w 
                  INNER JOIN comp t ON w.wcl = t.cmp AND  w.wc = t.cm
                  INNER JOIN pers b ON w.ID = b.ID_l 
                  INNER JOIN pn p ON b.ID = p.ID 
                  AND t.cp=:cp group";  
  
                  $query = $glb_connection-&gt;prepare($sql);
                  $query-&gt;bindValue(':cp',$cp);
                  $query-&gt;execute();
                  $wes = $query-&gt;fetchAll();
  
                  // First array Generated from sql1 query 
                      $newCorr = array();
                  foreach ($wes as $option) {
                      $wclID = $option['desc'];
                      $nameF = $option['fname'];
                      $nameL = $option['lname'];
                      $id = $option['ID'];
                      $newCorr[$wclID][$id] = $nameL." ".$nameF;
                  }
  
                   $sql2 = "SELECT p.ID, e.enre w.ID, p.fname, p.lname, w.desc FROM weight w 
                  INNER JOIN comp t ON w.wcl = t.cmp AND  w.wc = t.cm
                  INNER JOIN pers b ON w.ID = b.ID_l 
                  INNER JOIN pn p ON b.ID = p.ID 
                  INNER JOIN t_ent e ON e.ID = p.ID
                  AND t.cp=:cp group";  
  
                  $query = $glb_connection-&gt;prepare($sql2);
                  $query-&gt;bindValue(':ID_cmp',$ID_cmp);
                  $query-&gt;execute();
                  $wes1 = $query-&gt;fetchAll();
  
                  //the second array from sql2 query 
                      $newCorrAc = array();
                  foreach ($wes1 as $option) {
                      $wc = $option['desc'];
                      $ent = $option['enre'];
                      $nameF = $option['fname'];
                      $nameL = $option['lname'];
                      $id = $option['ID'];
                      $newCorrAc [$wc] [$id] [$ent]= $nameL." ".$nameF;
                  }
  
              //the form will generate after here here
                  $html_form = '';
  
                  if(count($newCorr) == 0){
  
                      $html_form .= '&lt;p&gt;'.boz(_('Not Found!')).'&lt;/p&gt;';
                  } else {    
  
                      $html_form .= '&lt;form  id="checkEnt" name="checkEnt" method="post" action="r.php?cp=&lt;?=$cp?&gt;"&gt;';
                      $html_form .= '&lt;input type="hidden" value="checkEntrance" name="ent"&gt;';
                      $html_form .= '&lt;table class="table zebra-striped table-bordered table-striped span8"&gt;';
                      $html_form .= '&lt;tbody&gt;';
  
                      foreach ($newCorr as $orgKey =&gt; $list) { 
                          $html_form .= '&lt;tr&gt;&lt;td width="5%"&gt;';
                          $html_form .= '&lt;h5&gt;'.$orgKey.'kg&lt;/h5&gt;';
                          $html_form .= '&lt;/td&gt;
                          &lt;td width="10%"&gt;
                          &lt;label class="control-label" for="inputWei"&gt;Boxer&lt;/label&gt;';  
                          $html_form .= '&lt;select class="input-xlarge" id="input" name="drop[0][]"&gt;';   
                          $html_form .= '&lt;option value=""&gt;Select&lt;/option&gt;';
                          foreach ($list as $key =&gt; $value) {
                              $html_form .= '&lt;option value='.$key.'&gt;'.$value.'&lt;/option&gt;';
  
                          } 
                          $html_form .= '&lt;/select&gt;
                          &lt;/td&gt;
                          &lt;td width="10%"&gt;
                          &lt;label class="control-label" for="inputWei"&gt;Res&lt;/label&gt;
                          &lt;select class="input-xlarge" name="drop[1][]"&gt;';
                          $html_form .= '&lt;option value=""&gt;Select&lt;/option&gt;
                          &lt;option value="en"&gt;Ent&lt;/option&gt;
                          &lt;option value="re"&gt;Res&lt;/option&gt;
                          &lt;/select&gt;
                          &lt;/td&gt;
                          &lt;/tr&gt;';
                      }
  
                      $html_form .= '&lt;tr&gt;&lt;td colspan="3"&gt;
                      &lt;div class="modal-footer"&gt;
                      &lt;button type=reset class="btn btn-danger"&gt;Reset&lt;/button&gt;
                      &lt;button class="btn btn-primary" ID="btnSaveBoxer"&gt;Save&lt;/button&gt;
                      &lt;/div&gt;
                      &lt;/td&gt;
                      &lt;/tr&gt; 
                      &lt;/tbody&gt;
                      &lt;/table&gt; 
                      &lt;/form&gt;';   
                  }             
                  echo $html_form;
  
              } catch(PDOException $e) {
                  addError($e-&gt;getMessage(), "MySql-Error", "error");
              }
          }
  &lt;/pre&gt;
  </code></pre>
  
  <p>what it does is exactly ...the First SQL returns array in FetchAll method, and after a bit of change the result will be like this... </p>
  
  <p>// First Query Result array check this line<br>
  $newCorr[$wclID][$id] = $nameL." ".$nameF; </p>
  
  <pre><code>&lt;pre&gt;
  Array
  (
      [4-6] =&gt; Array
          (
              [87] =&gt; haha lala
          )
  
      [8] =&gt; Array
          (
              [25] =&gt; sasa baba
              [24] =&gt; mama fafa
              [26] =&gt; tata lala
          )
  
      [5] =&gt; Array
          (
              [29] =&gt; papa oaoa
              [27] =&gt; laha mana
              [30] =&gt; salam sara
          )
  
      [2] =&gt; Array
          (
              [33] =&gt; tata kaka
              [32] =&gt; lala sasa
              [31] =&gt; Papa lama
              [34] =&gt; wana michel
          )
  
      [6] =&gt; Array
          (
              [35] =&gt; zaza yaya
              [37] =&gt; wana mata
              [36] =&gt; Kaku luba
          )
  
  )
  &lt;/pre&gt;
  </code></pre>
  
  <p>from the above code as you can see, I generate dropdown form, which filled from the above array.</p>
  
  <p>What problem I have faced is, after the customer enter the form data, when I need to populate the form as it is except the customer choice must be selected as default...</p>
  
  <p>So, what i did is i use second SQL2, which generates the following array, this array is exactly what the customer enter it.</p>
  
  <p>// Second Query Result Array
  $newCorrAc [$wc] [$id] [$ent]= $nameL." ".$nameF;</p>
  
  <pre><code>&lt;pre&gt;
  Array
  (
      [8] =&gt; Array
          (
              [26] =&gt; Array
                  (
                      [ent] =&gt; tata lala
                  )
  
          )
  
      [2] =&gt; Array
          (
              [31] =&gt; Array
                  (
                      [res] =&gt; papa lama
                  )
  
          )
  
  ) 
  &lt;/pre&gt;
  </code></pre>
  
  <p>The main question is, how do I be able to fill the forms from his/her previous enter data when the drop down populated again?</p>
  
  <p>In short what i want to do is, the form is submited, and i have link for correction. if clicked it should show the same form except with the entered data previously, that can be get from database.</p>
  
  <p>some Idea please?</p>