Advertisement
Guest User

Untitled

a guest
May 14th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.70 KB | None | 0 0
  1. <!DOCTYPE html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <meta http-equiv="X-UA-Compatible" content="IE=edge">
  6. <meta name="viewport" content="width=device-width, initial-scale=1">
  7. <meta name="description" content="">
  8. <meta name="author" content="">
  9. <title>Passing Data To Modal</title>
  10. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u" crossorigin="anonymous">
  11. </head>
  12.  
  13. <body>
  14. <div class="container">
  15. <div class="row">
  16. <table class="table table-bordered">
  17. <tr>
  18. <th>No</th>
  19. <th>Nama Pengguna</th>
  20. <th>Email Pengguna</th>
  21. <th>Password Pengguna</th>
  22. <th>Opsi</th>
  23. </tr>
  24. <?php
  25. $servername = "localhost";
  26. $username = "root";
  27. $password = "";
  28. $dbname = "db_guide";
  29.  
  30. // Membuat Koneksi
  31. $koneksi = new mysqli($servername, $username, $password, $dbname);
  32.  
  33. // Melakukan Cek Koneksi
  34. if ($koneksi->connect_error) {
  35. die("Koneksi Gagal : " . $koneksi->connect_error);
  36. }
  37.  
  38. //Melakukan query
  39. $sql = "SELECT * FROM user";
  40. $hasil = $koneksi->query($sql);
  41. $no = 1;
  42. if ($hasil->num_rows > 0) {
  43. foreach ($hasil as $row) { ?>
  44. <tr>
  45. <td><?php echo $no; ?></td>
  46. <td><?php echo $row['nama']; ?></td>
  47. <td><?php echo $row['email']; ?></td>
  48. <td><?php echo $row['psw']; ?></td>
  49.  
  50. <?php echo "<td><a href='updateuser.php' class='btn btn-default btn-small' id='custId' data-toggle='modal' data-id=".$row['kode_user'].">Detail</a></td>"; ?>
  51. </tr>
  52. <?php
  53. $no++;
  54. }
  55. } else {
  56. echo "0 results";
  57. } $koneksi->close();
  58. ?>
  59.  
  60. </table>
  61. </div>
  62. </div>
  63.  
  64. <div class="modal fade" id="myModal" role="dialog">
  65. <div class="modal-dialog" role="document">
  66. <div class="modal-content">
  67. <div class="modal-header">
  68. <button type="button" class="close" data-dismiss="modal">&times;</button>
  69. <h4 class="modal-title">User Detail</h4>
  70. </div>
  71. <div class="modal-body">
  72. <div class="fetched-data"></div>
  73. </div>
  74. <div class="modal-footer">
  75. <button type="button" class="btn btn-default" data-dismiss="modal">Keluar</button>
  76. </div>
  77. </div>
  78. </div>
  79. </div>
  80.  
  81. <script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
  82. <script type="text/javascript">
  83. $(document).ready(function(){
  84. $('#myModal').on('show.bs.modal', function (e) {
  85. var rowid = $(e.relatedTarget).data('id');
  86. //menggunakan fungsi ajax untuk pengambilan data
  87. $.ajax({
  88. type : 'post',
  89. url : 'detail.php',
  90. data : 'rowid='+ rowid,
  91. success : function(data){
  92. $('.fetched-data').html(data);//menampilkan data ke dalam modal
  93. }
  94. });
  95. });
  96. });
  97. </script>
  98. <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js" integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa" crossorigin="anonymous"></script>
  99. </body>
  100. </html>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement