Bootstrap modal

Hello,

I need help on bootstrap modal. Suppose, a table contains 5 rows.[table=“width: 500”]

[tr]
	[td]Student Name[/td]
	[td]Profile[/td]
[/tr]

<?
/=== Query from student table ===//
<? while($row = mysql_fetch_array($result)) { ?> 

[tr]
	[td]Student Name[/td]
	[td]<button data-toggle="modal" href="#view-student" class="btn btn-toolbar btn-sm"  data-id="<?=$row['id']?>">View Profile</button>[/td]
[/tr]

<? } ?>

[/table]

In above table inside the while loop, first col shows student name and 2nd col shows view profile button.
when i click view profile button then it calls modal and will show me student details information. In this way when i click view profile button of 2nd student then it call modal and will show me student details of 2nd student. But my problem is i can’t do this. I need view profile button will be dynamic. How can i do this ?? Can you please help me??

//modal function of view student

<?php
$resultV = mysql_query("SELECT * FROM student WHERE id =$ID"); // Here i need dynamic id
$row = mysql_fetch_array($resultV);
?>
  <!-- Modal -->
  <div class="modal fade" id="view-student" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
    <div class="modal-dialog"  style=" width:950px;">
      <div class="modal-content">
        <div class="modal-header">
       
        </div>
        <div class="modal-body">
         <table  class="table">
             /* Table content display student information */
         </table>
         </div>
</div>
</div>
</div>

In present situation this modal i can’t make it dynamic. I need help to make it dynamic. That means modal display individual student information dynamically.

Thanks,
Rima.

Hi Rima,

If you only have a small number of rows, the easiest way to do this would be to create a separate modal for each row:


<?php
foreach ($students as $student) {
?>
    <div class="modal fade" id="view-student-<?php echo $student['id'] ?>" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true" >
    // rest of the modal html
<?php
}

Note that you need to make the ID of each modal unique (here I’m using the student record ID).