jeudi 15 novembre 2018

How to add checkbox on my pagination page, generated from database?

Sorry to bother but I have some curiosity over to how to do checkbox on my pagination page. Now, I'm sure that this must be really easy to do but I couldn't grasp the method at all although I have done few readings and trial and error on some of the available codes online like: Submit Checkbox Value, Fetch data from database as checkbox, checkbox in pagination and many more.

So...I want to ask anyone here if they can give me guidance on how to do this right.

Here is my candidate.php

<script>
  function Pagination() {
    $("#pagination").twbsPagination({
      totalPages: <?php echo $total_pages; ?>,
      visible: 5,
      onPageClick: function (e, page) {
        e.preventDefault();
        $("#target-content").html("loading....");
        $("#target-content").load("candidatepagination.php?page="+page);
      }
    });
  }
</script>

<script>
  $(function () {
      Pagination();
  });
</script>

<script>
  $("#searchBtn").on("click", function(e) {
    e.preventDefault();
    var searchResult = $("#searchBar").val();
    var filter = "searchBar";
    if(searchResult != "") {
      $("#pagination").twbsPagination('destroy');
      Search(searchResult, filter);
    } else {
      $("#pagination").twbsPagination('destroy');
      Pagination();
    }
  });
</script>

<script>
  $(".experienceSearch").on("click", function(e) {
    e.preventDefault();
    var searchResult = $(this).data("target");
    var filter = "experience";
    if(searchResult != "") {
      $("#pagination").twbsPagination('destroy');
      Search(searchResult, filter);
    } else {
      $("#pagination").twbsPagination('destroy');
      Pagination();
    }
  });
</script>

<script>
  $(".citySearch").on("click", function(e) {
    e.preventDefault();
    var searchResult = $(this).data("target");
    var filter = "city";
    if(searchResult != "") {
      $("#pagination").twbsPagination('destroy');
      Search(searchResult, filter);
    } else {
      $("#pagination").twbsPagination('destroy');
      Pagination();
    }
  });
</script>

<script>
  function Search(val, filter) {
    $("#pagination").twbsPagination({
      totalPages: <?php echo $total_pages; ?>,
      visible: 5,
      onPageClick: function (e, page) {
        e.preventDefault();
        val = encodeURIComponent(val);
        $("#target-content").html("loading....");
        $("#target-content").load("search.php?page="+page+"&search="+val+"&filter="+filter);
      }
    });
  }
</script>
 <section id="candidates" class="content-header">
      <div class="container">
        <div class="row">
          <div class="col-md-3">
            <div class="box box-solid">
              <div class="box-body no-padding">
                
                
                    
              </div>
            </div>
          </div>
          <div class="col-md-9">

          <?php

          $limit = 4;

          $sql = "SELECT COUNT(id_user) AS id FROM users";
          $result = $conn->query($sql);
          if($result->num_rows > 0)
          {
            $row = $result->fetch_assoc();
            $total_records = $row['id'];
            $total_pages = ceil($total_records / $limit);
          } else {
            $total_pages = 1;
          }

          ?>

          
            <div id="target-content">
              
            </div>
            <div class="text-center">
              <ul class="pagination text-center" id="pagination"></ul>
            </div> 



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

here is where the query will fetch the data from database and displayed it so users can look at the candidate and choose suitable candidate for them.

and here is my candidatepagination.php

<?php

session_start();

require_once("db.php");

$limit = 4;

if(isset($_GET["page"])){
        $page = $_GET['page'];
}else {
        
        $page=1;
}

        $start_from = ($page-1) * $limit;
        
        $sql = "SELECT * FROM users LIMIT $start_from, $limit";
        $result = $conn-> query($sql);
        
        if($result->num_rows > 0){
                while($row = $result -> fetch_assoc ()) {?>
                
                <div class="attachment-block clearfix">
                        <img class="attachment-img" src="uploads/office/britay.png" alt="Attachment Image">
                                <div class="attachement-pushed">
                                <div class="attachement-text">
                                        <div><strong>BA<?php echo $row['id_user']; ?></strong></div>
                                </div>
                                        <div><?php echo $row['aboutme'] ?></div>
                                </div>
                </div>
                <?php
                }
                
        }
$conn->close();

so, can anyone tell me where should I put the checkbox and how can the checkbox be saved into the database?




Aucun commentaire:

Enregistrer un commentaire