Hi I'm passing php variable to twitter boostrap modal. but I cant get the right id when I click the link inside the modal. please see code below. first I have created a foreach function where data loops second I have created a link to show the modal 3rd I have actions link inside the modal where user can update, delete the data. what I have achieve already is that I can pass the variable of php going to modal actions, but when I try to other rows it shows the same id still.
<table class="table table-condensed table-bordered table-striped volumes">
<thead>
<tr>
<th>ID</th>
<th>Director</th>
<th>Address</th>
</tr>
</thead>
<tbody>
<?php
foreach ($natcco_members as $nattco) {
$id = $nattco['id'];
echo "<tr>
<td>".++$counter."</td>
<td>".$nattco['director']."</td>
<td><a href='#' class='b'>".$nattco['agent_name']."</a></td>
<td>".$nattco['address']."</td>
</td>";
?>
<!-- Modal HTML -->
<div id="myModal" class="modal fade">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title">Choose your actions!</h4>
</div>
<div class="modal-body" align="center">
<a href='update_sub_agent.php?id=<?php echo urlencode(htmlspecialchars($id)) ?>' class='btn btn-success'><i class='icon-pencil'></i> Edit</a>
<a href='owner.php?id=".urlencode(htmlspecialchars($id))."' class='btn btn-info'><i class='icon-user'></i> Owner</a>
<a href='fla.php?id=".urlencode(htmlspecialchars($id))."' class='btn btn-warning'><i class='icon-list-alt'></i> FLA</a>
<a href='delete.php?id=".urlencode(htmlspecialchars($id))."' class='btn btn-danger'><i class='icon-remove'></i> Delete</a>
</div>
<div class="modal-footer">
</div>
</div>
</div>
</div>
<?php "</tr>";
}
}
?>
</tbody>
</table>
See Question&Answers more detail:os