Passing unique id from a list with buttons clicked to a bootstrap modal
<p>I have this list of feeds and at the end of the list I have buttons to update, change status of a feed. </p>

<p><a href="https://i.stack.imgur.com/LGLhE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/LGLhE.png" alt="List of Feeds"></a></p>

<p>When I click on "Suspend" a feed - the id of that feed is not past to the modal.I always get the last value from the list for any of the button feeds I choice. </p>

<p><a href="https://i.stack.imgur.com/pg4ZA.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/pg4ZA.png" alt="modal feed"></a></p>

<p>How can I pass an id value of a specific feed to the modal?</p>

<p>Here is the code of the modal with the javascript to call the backend.</p>

<pre><code> &lt;div class="modal fade" id="statusModal" tabindex="-1" role="dialog" aria-labelledby="statusModalLabel" 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;&lt;/button&gt;
            &lt;h4 class="modal-title" id="statusModalLabel"&gt;Please confirm&lt;/h4&gt;
        &lt;/div&gt;

        &lt;div class="modal-body"&gt;
            &lt;form id="change_status" name="change_status" action="#" method="post"&gt;
                &lt;input type="hidden" name="mode" value="change_status"&gt;
                &lt;input type="hidden" name="cid" value="&lt;? echo $feed['id'] ?&gt;"&gt;
                &lt;fieldset&gt;
                &lt;legend&gt;&lt;/legend&gt;
                &lt;h4&gt;Change the frequence of the feed&lt;/h4&gt;
                &lt;br/&gt;
               &lt;label for="content_type"&gt;&lt;span class="required"&gt;*&lt;/span&gt;&lt;?php echo __('feeds:checktime') ?&gt;&lt;/label&gt;
                &lt;select name="cchecktime" class="form-control"&gt;
                &lt;?php
                    foreach ($checktimes as $checktime) {
                        echo '&lt;option value="' . $checktime['time'] . '"&gt;' . $checktime['title']    . '&lt;/option&gt;';
                    }
                ?&gt;
                &lt;/select&gt;
            &lt;/fieldset&gt;
            &lt;/form&gt;
        &lt;/div&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 id="change_feed_status" type="button" class="btn btn-primary"&gt;Confirm&lt;/button&gt;
        &lt;/div&gt;
    &lt;/div&gt;&lt;!-- /.modal-content --&gt;
 &lt;/div&gt;&lt;!-- /.modal-dialog --&gt;
&lt;/div&gt;&lt;!-- /.modal --&gt;

&lt;script type="text/javascript"&gt;
$("#change_feed_status").on("click", function(){
  var $form = $(this);
  $("#change_feed_status").replaceWith("&lt;em&gt;sending...&lt;/em&gt;");
  $.ajax({
    type: $form.attr('method'),
    url: 'media/feeds',
    data: $("#change_status").serialize(),
    success: function(data) 
    {
        if(data == "true") 
        {
            $("#change_status").fadeOut("fast", function()
            {
                $(this).before("&lt;p&gt;&lt;strong&gt;Success! Your project have been added&lt;/strong&gt;&lt;/p&gt;");
                setTimeout("$.fancybox.close()", 2000);
                window.location.href=window.location.href;
            });
        }
    }
  });
 });
&lt;/script&gt;
</code></pre>

<p>Here is the code when I list the feeds</p>

<pre><code>  &lt;h2 class="green_title"&gt;&lt;?php echo $count; ?&gt; Feeds in the database&lt;/h2&gt;
     &lt;table class="table table-striped"&gt;
      &lt;thead&gt;
        &lt;th&gt;&lt;?php echo __('feeds:title') ?&gt;&lt;/th&gt;
        &lt;th&gt;&lt;?php echo __('feeds:lastchecked') ?&gt;&lt;/th&gt;
        &lt;th&gt;&lt;?php echo __('feeds:lastnoarticles') ?&gt;&lt;/th&gt;
        &lt;th&gt;&lt;?php echo __('feeds:issue') ?&gt;&lt;/th&gt;
        &lt;th&gt;&lt;?php echo __('feeds:checktime') ?&gt;&lt;/th&gt;
        &lt;th&gt;&lt;?php echo __('feeds:active') ?&gt;&lt;/th&gt;
        &lt;!--&lt;th&gt;Date checked&lt;/th&gt;--&gt;
        &lt;th&gt;&lt;?php echo __('global:actions') ?&gt;&lt;/th&gt;
       &lt;/thead&gt;
     &lt;tbody&gt;
    &lt;?php foreach ($feeds as $feed) { 
    ?&gt;
    &lt;tr&gt;
      &lt;td&gt;&lt;b&gt; &lt;?php echo $feed['title'] ?&gt;&lt;/b&gt;&lt;br&gt;
     &lt;?php echo $feed['feedtype']; ?&gt;
     &lt;/td&gt;
     &lt;td&gt; 
     &lt;?php echo gmdate("Y-m-d H:i:s", $feed['lastchecked']); ?&gt;
     &lt;/td&gt;
     &lt;td&gt;
        &lt;ul class="list-group"&gt;
            &lt;li class="list-group-item"&gt;
                &lt;span class="badge"&gt;&lt;?php echo $feed['lastnoarticles'] ?&gt;&lt;/span&gt;New
            &lt;/li&gt;
        &lt;/ul&gt;
        &lt;/td&gt;

        &lt;td&gt; 
            &lt;?php echo $feed['issue']; ?&gt;
        &lt;/td&gt;
        &lt;td&gt;
            &lt;?php
            if($feed['checktime'] == 0xFFFFFFFF) {
            ?&gt;
                &lt;span class="label label-info"&gt;&lt;?php echo __('feeds:once') ?&gt;&lt;/span&gt;
             &lt;?php
        } elseif($feed['checktime'] == 0) {
        ?&gt; 
            &lt;span class="label label-info"&gt;&lt;?php echo __('feeds:every5minutes') ?&gt;&lt;/span&gt;
        &lt;?php
        } elseif($feed['checktime'] == 900) {
        ?&gt; 
            &lt;span class="label label-info"&gt;&lt;?php echo __('feeds:every15minutes') ?&gt;&lt;/span&gt;
        &lt;?php
        } elseif($feed['checktime'] == 3600) {
        ?&gt; 
            &lt;span class="label label-info"&gt;&lt;?php echo __('feeds:everyhour') ?&gt;&lt;/span&gt;
        &lt;?php
        } elseif($feed['checktime'] == 86400) {
        ?&gt; 
            &lt;span class="label label-info"&gt;&lt;?php echo __('feeds:everyday') ?&gt;&lt;/span&gt;
        &lt;?php
        } elseif($feed['checktime'] == 604800) {
        ?&gt; 
            &lt;span class="label label-info"&gt;&lt;?php echo __('feeds:everyweek') ?&gt;&lt;/span&gt;
        &lt;?php
        }
        ?&gt; 
    &lt;/td&gt;
    &lt;td&gt;
        &lt;?php
        if($feed['checktime'] == 0xFFFFFFFF) {
        ?&gt;
            &lt;span class="label label-danger"&gt;&lt;?php echo __('feeds:notactive') ?&gt;&lt;/span&gt;
         &lt;?php
         } else {
        ?&gt; 
            &lt;span class="label label-success"&gt;&lt;?php echo __('feeds:active') ?&gt;&lt;/span&gt;
         &lt;?php
         }
         ?&gt; 
    &lt;/td&gt;

    &lt;td&gt;
    &lt;!-- Split button --&gt;
        &lt;div class="btn-group"&gt;
            &lt;button type="button" class="btn btn-info" data-toggle="modal" data-target="#showFeed"  data-id="&lt;? echo $feed['id'] ?&gt;"&gt;&lt;?php echo __('feeds:feedshow') ?&gt;&lt;/button&gt;    

            &lt;button type="button" class="btn btn-success" data-toggle="modal" data-target="#editModal" value="&lt;? echo $feed['id'] ?&gt;"&gt;&lt;?php echo __('feeds:feededit') ?&gt;&lt;/button&gt;

            &lt;?php
            if($feed['checktime'] == '4294967295') {
            ?&gt; 
                &lt;button type="button" class="btn btn-success" data-toggle="modal" data-target="#statusModal" title="&lt;? echo $feed['id'] ?&gt;"&gt;&lt;?php echo __('feeds:feedactivate') ?&gt;&lt;/button&gt;
            &lt;?php
            } else {
            ?&gt; 
                    &lt;button type="button" class="btn btn-warning" data-toggle="modal" data-target="#statusModal" title="&lt;? echo $feed['id'] ?&gt;"&gt;&lt;?php echo __('feeds:feedsuspend') ?&gt;&lt;/button&gt;
            &lt;?php
              }
              ?&gt;
                &lt;button type="button" class="btn btn-primary" data-placement="top" data-toggle="modal" title="Update" data-target="#updateFeed" data-id="&lt;? echo $feed['id'] ?&gt;"&gt;&lt;?php echo __('feeds:feedupdate') ?&gt;&lt;/button&gt;
            &lt;/div&gt;
         &lt;/td&gt;
     &lt;/tr&gt;
    &lt;?php
     }
    ?&gt;  
    &lt;/tbody&gt;
    &lt;/table&gt;
</code></pre>