PageRenderTime 26ms CodeModel.GetById 14ms RepoModel.GetById 0ms app.codeStats 0ms

/view/listmhs.php

https://gitlab.com/nova0893/androidevelop
PHP | 161 lines | 117 code | 42 blank | 2 comment | 9 complexity | e4827e39bb1db478b099fd7175d956f3 MD5 | raw file
  1. <?php
  2. include('../config/koneksi.php');
  3. //for total count data
  4. $query = $pdo->prepare( "SELECT COUNT(oid) FROM ms_mhs");
  5. $query->execute();
  6. while($r = $query->fetch()) {
  7. $total_records = $r[0];
  8. }
  9. $total_pages = ceil($total_records / $limit);
  10. //for first time load data
  11. if (isset($_GET["page"])) { $page = $_GET["page"]; } else { $page=1; };
  12. $start_from = ($page-1) * $limit;
  13. $query = $pdo->prepare ("SELECT * FROM ms_mhs ORDER BY `str_nm_mhs` ASC LIMIT $start_from, $limit");
  14. $query->execute();
  15. ?>
  16. <?php include('header.php');?>
  17. <!DOCTYPE html>
  18. <html>
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  21. <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.0/css/bootstrap.min.css">
  22. <script type="text/javascript" charset="utf8" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.0.3.js"></script>
  23. <script type="text/javascript" src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
  24. <link rel="stylesheet" href="dist/simplePagination.css" />
  25. <script src="dist/jquery.simplePagination.js"></script>
  26. <title></title>
  27. <script>
  28. </script>
  29. </head>
  30. <body>
  31. <div class="container" >
  32. <h1>Daftar Mahasiswa</h1>
  33. <form action="" method="get">
  34. <input type="text" class="form-control input-sm" maxlength="8" name="search" required autocomplete="off" placeholder="Cari Berdasarkan NPM/Nama">
  35. </br>
  36. <div class='fa fa-search'>
  37. <div class="col-sm-12">
  38. <button type="submit" class="btn btn-success"><i class="fa fa-search"></i> Cari Data</button>
  39. </div>
  40. </div>
  41. </br></br>
  42. </form>
  43. <table class="table table-bordered table-striped">
  44. <thead>
  45. <tr>
  46. <th>No</th>
  47. <th>NPM</th>
  48. <th>Nama</th>
  49. <th>Alamat</th>
  50. <th align="center">Akses</th>
  51. </tr>
  52. </thead>
  53. <tbody id="target-content">
  54. <?php
  55. $no = 1;
  56. if(isset($_GET['search'])){
  57. $param = $_GET['search'];
  58. $query = $pdo->prepare("SELECT * FROM ms_mhs WHERE `str_npm` LIKE :param OR `str_nm_mhs` LIKE :param ORDER BY `str_nm_mhs` LIMIT $start_from, $limit" );
  59. $query->bindValue(':param', '%'.$param.'%', PDO::PARAM_STR);
  60. $query->execute();
  61. if($query->rowCount() > 0 ){
  62. $no=1;
  63. while ($r = $query->fetch()) {
  64. echo '<tr>
  65. <td>'.$no.'</td>
  66. <td>'.$r['str_npm'].'</td>
  67. <td>'.$r['str_nm_mhs'].'</td>
  68. <td>'.$r['str_almt_rmh'].'</td>
  69. <td align="center"> <a href="vdetail/detailmhs.php?str_npm='.$r['str_npm'].'">'.'Lihat Detail </a>'.'</td>
  70. </tr>';
  71. ++$no;
  72. }//end while
  73. }else{
  74. echo "<tr><td colspan=\"4\">Not Found</td></tr>";
  75. }
  76. }//end if
  77. while ($r = $query->fetch()) {
  78. echo '<tr>
  79. <td>'.$no.'</td>
  80. <td>'.$r['str_npm'].'</td>
  81. <td>'.$r['str_nm_mhs'].'</td>
  82. <td>'.$r['str_almt_rmh'].'</td>
  83. <td align="center"> <a href="vdetail/detailmhs.php?str_npm='.$r['str_npm'].'">'.'Lihat Detail </a>'.'</td>
  84. </tr>';
  85. ++$no;
  86. }//end while
  87. ?>
  88. </tbody>
  89. </table>
  90. <nav><ul class="pagination">
  91. <?php if(!empty($total_pages)):for($i=1; $i<=$total_pages; $i++):
  92. if($i == 1):?>
  93. <li class='active' id="<?php echo $i;?>"><a href='vpagination/pagination.php?page=<?php echo $i;?>'><?php echo $i;?></a></li>
  94. <?php else:?>
  95. <li id="<?php echo $i;?>"><a href='vpagination/pagination.php?page=<?php echo $i;?>'><?php echo $i;?></a></li>
  96. <?php endif;?>
  97. <?php endfor;endif;?>
  98. </ul></nav>
  99. </div>
  100. </body>
  101. <script type="text/javascript">
  102. $(document).ready(function(){
  103. $('.pagination').pagination({
  104. items: <?php echo $total_records;?>,
  105. itemsOnPage: <?php echo $limit;?>,
  106. cssStyle: 'light-theme',
  107. currentPage : 1,
  108. onPageClick : function(pageNumber) {
  109. jQuery("#target-content").html('loading...');
  110. jQuery("#target-content").load("vpagination/pagination.php?page=" + pageNumber);
  111. }
  112. });
  113. });
  114. </script>
  115. <?php
  116. include('footer.php');
  117. ?>