Modal为所有记录弹出相同的信息

I am looping a DIV with foreach loop. my PHP looks like this:

   <?php foreach ($record as $row) { //looping the records ?>
   <button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal">
     Launch demo modal
    </button>

    <div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
    <div class="modal-dialog" role="document">
        <h4><?php echo get_userdetails_byid($row['user_id']); ?></h4>
    </div>
    </div>
   <?php } ?>

And the modal always show the first entry of the loop.. however in the html source code i can see all the records. How do i trigger each result individually?

data-target="#myModal" will use the id attribute. And multiple elements can not have the same id. Use different id for different modal.

<?php
     $i = 0; 
     foreach ($record as $row) { //looping the records 
?>
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target="#myModal<?php echo $i;?>">
 Launch demo modal
</button>

<div class="modal fade" id="myModal<?php echo $i;?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
<div class="modal-dialog" role="document">
    <h4><?php echo get_userdetails_byid($row['user_id']); ?></h4>
</div>
</div>
<?php 
    $i++;
 } 
?>