title: PHP Foreach loop passing data onto jquery modal for form use
body: <p>I am using Bootstrap with Codeigniter. I have a table that loads block history for an account on the management interface I'm building. On each of the rows as part of the foreach, there is an "unblock" button if the user can remove that block as you'll hopefully see in the below example. The button specifically is <code>&lt;td&gt;&lt;?php if ($bd['expiredate'] &gt; date('Y-m-d H:i:s')) { ?&gt;&lt;button type="button" class="btn btn-info" data-toggle="modal" data-target="#delBlock" &lt;?php if ($check_perm['unbanaccount'] == 0 || $bd['unblock_date'] &gt; 0) { echo "disabled"; } ?&gt; &gt;Unblock&lt;/button&gt;&lt;?php } ?&gt;&lt;/td&gt;</code></p>
  
  <pre><code>        &lt;div class="table-responsive"&gt;
              &lt;table class="table table-striped table-bordered table-hover" id="dataTables-example"&gt;
                  &lt;thead&gt;
                      &lt;tr&gt;
                          &lt;th style="width: 125px;"&gt;Block Date&lt;/th&gt;
                          &lt;th style="width: 100px;"&gt;Blocked By&lt;/th&gt;
                          &lt;th style="width: 125px;"&gt;Expiry Date&lt;/th&gt;
                          &lt;th style="width: 100px;"&gt;Reason&lt;/th&gt;
                          &lt;th style="width: 100px;"&gt;Unblocked By&lt;/th&gt;
                          &lt;th style="width: 125px;"&gt;Unblocked Date&lt;/th&gt;
                          &lt;th style="width: 30px;"&gt;Block&lt;br /&gt;Comment&lt;/th&gt;
                          &lt;th style="width: 30px;"&gt;Unblock&lt;br /&gt;Comment&lt;/th&gt;
                          &lt;th style="width: 100px;"&gt;Options&lt;/th&gt;
                      &lt;/tr&gt;
                  &lt;/thead&gt;
                  &lt;tbody&gt;
                      &lt;?php if (empty($block_list)) { echo "&lt;tr class='odd gradeX'&gt;&lt;td colspan='9'&gt;&lt;center&gt;No data!&lt;/center&gt;&lt;/td&gt;&lt;/tr&gt;"; } ?&gt;
                      &lt;?php foreach ($block_list as $bd): ?&gt;
                          &lt;tr class="odd gradeX"&gt;
                              &lt;td&gt;&lt;?php echo $bd['blockdate']; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo $bd['blockname']; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo $bd['expiredate']; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo $bd['reason']; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo $bd['ublockname']; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php echo $bd['unblock_date']; ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;center&gt;&lt;a data-toggle="collapse" data-parent="#accordion" href="#blockcomment&lt;?php echo $bd['blockid']; ?&gt;"&gt;&lt;button type="button" class="btn btn-primary btn-circle"&gt;&lt;i class="fa fa-list"&gt;&lt;/i&gt;&lt;/button&gt;&lt;/a&gt;&lt;/center&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php if (isset($bd['unblock_date']) == TRUE) { ?&gt;&lt;center&gt;&lt;a data-toggle="collapse" data-parent="#accordion" href="#ublockcomment&lt;?php echo $bd['blockid']; ?&gt;"&gt;&lt;button type="button" class="btn btn-primary btn-circle"&gt;&lt;i class="fa fa-list"&gt;&lt;/i&gt;&lt;/button&gt;&lt;/a&gt;&lt;/center&gt;&lt;?php } ?&gt;&lt;/td&gt;
                              &lt;td&gt;&lt;?php if ($bd['expiredate'] &gt; date('Y-m-d H:i:s')) { ?&gt;&lt;button type="button" class="btn btn-info" data-toggle="modal" data-target="#delBlock" &lt;?php if ($check_perm['unbanaccount'] == 0 || $bd['unblock_date'] &gt; 0) { echo "disabled"; } ?&gt; &gt;Unblock&lt;/button&gt;&lt;?php } ?&gt;&lt;/td&gt;
                          &lt;/tr&gt;
                          &lt;tr&gt;&lt;td colspan="9"&gt;
                              &lt;div id="blockcomment&lt;?php echo $bd['blockid']; ?&gt;" class="panel-collapse collapse"&gt;
                                  &lt;div class="panel-body"&gt;
                                      &lt;strong&gt;Block Comment:&lt;/strong&gt;&lt;br /&gt;&lt;?php echo $bd['block_comment']; ?&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div id="ublockcomment&lt;?php echo $bd['blockid']; ?&gt;" class="panel-collapse collapse"&gt;
                                  &lt;div class="panel-body"&gt;
                                      &lt;strong&gt;Unblock Comment:&lt;/strong&gt;&lt;br /&gt;&lt;?php echo $bd['unblock_comment']; ?&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                          &lt;/td&gt;&lt;/tr&gt;
                      &lt;?php endforeach; ?&gt;
                  &lt;/tbody&gt;
              &lt;/table&gt;
              &lt;div align="right"&gt;&lt;button type="button" class="btn btn-warning" data-toggle="modal" data-target="#addBlock" &lt;?php if ($check_perm['banaccount'] == 0) { echo "disabled"; } ?&gt; &gt;Add New Block&lt;/button&gt;&lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>Once you click on the "Unblock" button if the account can be unblocked, I have a modal come up where you enter in a comment about your unblocking the user. Each block is referenced by a unique ID (the variable would be <code>$bd['blockid']</code> in the above example) in the database. It is this blockid that I need to communicate to the database and tell it which block to update data for, to state the user was unblocked on the table.</p>
  
  <p>The modal is the following:</p>
  
  <pre><code>        &lt;div class="modal fade" id="delBlock" tabindex="-1" role="dialog" aria-labelledby="delBlockLabel" aria-hidden="true"&gt;
              &lt;div class="modal-dialog"&gt;
                  &lt;div class="modal-content"&gt;
                      &lt;div class="modal-header"&gt;
                          &lt;button type="button" class="close" data-dismiss="modal" aria-hidden="true"&gt;&amp;times;&lt;/button&gt;
                          &lt;h4 class="modal-title" id="delBlockLabel"&gt;Remove Block&lt;/h4&gt;
                      &lt;/div&gt;
                      &lt;div class="modal-body"&gt;
                          &lt;?php echo validation_errors(); ?&gt;
                          &lt;?php echo form_open('/account/delblock', array('class' =&gt; 'form-inline'), array('blockid' =&gt; $bd['blockid'], 'acct_id' =&gt; $acct_data-&gt;account_id)); ?&gt;
                          &lt;table&gt;
                              &lt;tr&gt;&lt;td width="25%"&gt;&lt;label&gt;Unblock Comment&lt;/label&gt;&lt;/td&gt;
                              &lt;td width="450px"&gt;&lt;textarea class="form-control" name="unbanComments" rows="5" style="width:100%;"&gt;&lt;/textarea&gt;&lt;/td&gt;&lt;/tr&gt;
                          &lt;/table&gt;
                      &lt;/div&gt;
                      &lt;center&gt;&lt;div style="color:#EE0000; "&gt;Note this will remove the ban with immediate effect.&lt;/div&gt;&lt;/center&gt;
                      &lt;div class="modal-footer"&gt;
                          &lt;button type="button" class="btn btn-default" data-dismiss="modal"&gt;Close&lt;/button&gt;
                          &lt;button type="submit" class="btn btn-primary"&gt;Remove Block&lt;/button&gt;
                      &lt;/div&gt;
                      &lt;?php echo form_close(); ?&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
  </code></pre>
  
  <p>As you'll see, I'm using Codeigniter's Form Helper functions to post <code>array('blockid' =&gt; $bd['blockid'],</code> through the form so that I can manipulate just that record with my Codeigniter model. But, as the jQuery modal is not in the loop, it always takes the last record as the $bd['blockid'] instead of the actual record I'm wanting to manipulate (in this case, I have ID's of 7, 6 &amp; 5 (in that order), I click on the record for ID 7 and instead it changes 5). I need to hand the modal that specific $bd['blockid'] through to the form so that I can use it in my Codeigniter Model. How would I go about accomplishing something like this?</p>