I have a table which has a button in each row to show details of each record. what I need is to pass selected data row to modal.
here is my PHP code for display dat
What you need is an Ajax call inside $('#detail').on('show.bs.modal', function (e) { }
to fetch data against $row['id_site']
<script>
$(document).ready(function() {
$('#detail').on('show.bs.modal', function (e) {
var uniqueId = $(e.relatedTarget).data('id');
//Ajax Method
$.ajax({
type : 'post',
url : 'file.php', //Here you will fetch records
data : 'uniqueId='+ uniqueId, //Pass uniqueId
success : function(response){
$('.modal-title').html('Detail site ' + uniqueId);
$('.modal-body').html(response);
}
});
});
});
</script>
file.php
<?php
include 'koneksi.php';
if($_POST['uniqueId']) {
$uniqueId = $_POST['uniqueId']; //escape the string
$sql = "SELECT * FROM data_site WHERE id_site = '".$uniqueId."'";
$result = $conn->query($sql);
if($result->num_rows > 0){
while ($row = $result->fetch_assoc()) {
echo "<table>
<tr>
<td>ID Site </td>
<td>: $row[id_site]</td>
</tr>
<tr>
<td>Nama Site </td>
<td>: $row[name_site]</td>
</tr>
<tr>
<td>Witel</td>
<td>: $row[witel]</td>
</tr>
<tr>
<td>OLT Hostname </td>
<td>: $row[olt]</td>
</tr>
<tr>
<td>IP OLT </td>
<td>: $row[ip_olt]</td>
</tr>
<tr>
<td>Port OLT</td>
<td>: $row[port_olt]</td>
</tr>
<tr>
<td>IP ONT</td>
<td>: $row[ip_ont]</td>
</tr>
</table>
";
}
}
}
?>