<?php
require('db.php');
include "x.php";
?>
<!doctype html>
<html lang="en">
  <head>
    
     <?php include "include/meta.php"; ?>

     <?php include "include/css.php"; ?>

       <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.4.1/css/bootstrap.min.css">

  </head>
  <body>
<?php include "include/header.php"; ?>

 <?php 


        if (isset($_GET['pageno'])) {
            $pageno = $_GET['pageno'];
        } 
        else {
            $pageno = 1;
        }
        $no_of_records_per_page = 10;
        $offset = ($pageno-1) * $no_of_records_per_page;



        $total_pages_sql = "SELECT COUNT(*) FROM notice_table";
        $result = mysqli_query($con,$total_pages_sql);
        $total_rows = mysqli_fetch_array($result)[0];
        $total_pages = ceil($total_rows / $no_of_records_per_page);
   ?>
<section class="w3l-contact-breadcrum">
  <div class="breadcrum-bg py-sm-5 py-4">
    <div class="container py-lg-3">
      <h2>Notice</h2>
      <p><a href="index.php">Home</a> &nbsp; / &nbsp; Notice</p>
    </div>
  </div>
</section>


<div class="container">
  <div class="row">
        <div class="col-md-1">
      



    </div>
    <div class="col-md-10">
      <br>
    <div cla ss="well form-horizontal">

       <div class="row m-0">
        <br>
          <div class="col-md-12 p-0">
              <div class="table-responsive">
                  <table class="table table-hover table-bordered table-sm">
                      <thead>
                          <tr>
                              <th>Recent updates</th>
                          </tr>
                      </thead>
                      <tbody>
                          <?php
                             
                              $sql = "SELECT * FROM notice_table WHERE n_by = '$x' ORDER BY n_date DESC LIMIT $offset, $no_of_records_per_page";
                              $res_data = mysqli_query($con,$sql);
                              $c = 1;
                              while($rows = mysqli_fetch_array($res_data))


                             { 
      
                              ?>
                                  <tr>
                                      
                                      <td cla ss='text-left align-middle'>
                                   
                                          <div class="media text-muted pt-3">

                                          <p class="media-body pb-3 mb-0 lh-125 border-bottom "  style="padding: 0 10px; font-size: 15px;">
                                          <strong class="d-block text-gray-dark">
                                          <a href="notice_total.php?n=<?php echo $rows['n_sl']; ?>" target="_blank" title='Click to open'>
                                          <?php echo "$rows[n_title]"; ?>
                                          </a></strong><br>
                                          &#8195;<?php echo showDate($rows['n_date']); ?>
                                          &nbsp;<?php echo showTime($rows['n_time']); ?>
                                          </p>

                                          </div>
                                        </td>
                                     
                                  </tr>
                                <?php

                                  $c++;
                              }
                          ?>
                      </tbody>
                  </table>
            <ul class="pagination">
                <li><a href="?pageno=1">First</a></li>
                <li class="<?php if($pageno <= 1){ echo 'disabled'; } ?>">
                    <a href="<?php if($pageno <= 1){ echo '#'; } else { echo "?pageno=".($pageno - 1); } ?>">Prev</a>
                </li>
                <li class="<?php if($pageno >= $total_pages){ echo 'disabled'; } ?>">
                    <a href="<?php if($pageno >= $total_pages){ echo '#'; } else { echo "?pageno=".($pageno + 1); } ?>">Next</a>
                </li>
                <li><a href="?pageno=<?php echo $total_pages; ?>">Last</a></li>
            </ul>
           </div>

          </div>
        </div>
      </div>

    </div>
    <div class="col-md-1">
      



    </div>
  </div>
</div>

<?php include "include/footer.php"; ?>
<?php include "include/js.php"; ?>

</body>

</html>
<!-- // grids block 5 -->
<?php 

     function showDate($dt) 
     {
          $date=date_create();
          date_timestamp_set($date,
          strtotime("$dt"));
          return date_format($date,"M j, Y");
    }

    function showTime($t) 
     {
          $time=date_create();
          date_timestamp_set($time,
          strtotime("$t"));
          return date_format($time,"g:i a");
    }

 ?>