Snippets Collections
const paginate = (array) => {
  const itemsPerPage = 10;
  const numberOfPages = Math.ceil( array.length / itemsPerPage);

  // need to create an array of arrays [[10], [20], [30]] etc
  return Array.from({ length: numberOfPages }, (_, pageIndex) => {
    const startIndex = pageIndex * itemsPerPage;
    return array.slice(startIndex, startIndex + itemsPerPage);
  });

}

export default paginate
db.Order.aggregate([
    { '$match'    : { "company_id" : ObjectId("54c0...") } },
    { '$sort'     : { 'order_number' : -1 } },
    { '$facet'    : {
        metadata: [ { $count: "total" }, { $addFields: { page: NumberInt(3) } } ],
        data: [ { $skip: 20 }, { $limit: 10 } ] // add projection here wish you re-shape the docs
    } }
] )
<?php 				
$servername = "";
$username = "";
$password = "";
$dbname = "";
$conn = mysqli_connect($servername, $username, $password, $dbname);

$showRecordPerPage = 10;
	if(isset($_GET['page']) && !empty($_GET['page'])){
		$currentPage = $_GET['page'];
	}else{
		$currentPage = 1;
	}
	$startFrom = ($currentPage * $showRecordPerPage) - $showRecordPerPage;
	$totalEmpSQL = "SELECT * FROM sem";
	$allEmpResult = mysqli_query($conn, $totalEmpSQL);
	$totalEmployee = mysqli_num_rows($allEmpResult);
	$lastPage = ceil($totalEmployee/$showRecordPerPage);
	$firstPage = 1;
	$nextPage = $currentPage + 1;
	$previousPage = $currentPage - 1;
	$empSQL = "SELECT * FROM `sem` WHERE is_visible = 1 ORDER BY shortby LIMIT $startFrom, $showRecordPerPage ";
	$empResult = mysqli_query($conn, $empSQL);		
 ?>

<?php
	while($emp = mysqli_fetch_assoc($empResult)){
?>

<div class="reg-box1 mb-3">
	<a href="admin/<?php echo $emp["file_link"];?>" target="_blank">
		<div class="bg-grey02 ">
			<div class="reg-download-pdf">
				<span><i class="fa fa-file-pdf-o" aria-hidden="true"></i></span> <?php echo $emp["title"];?>
			</div>
		</div>
	</a>
</div>


<?php
	}
?>

<!-- pag -->
<nav aria-label="Page navigation example mt-5">
	<ul class="pagination justify-content-center">
		<li class="page-item <?php if($currentPage <= 1){ echo 'disabled'; } ?>">
			<a class="page-link"
			href="<?php if($currentPage <= 1){ echo '#'; } else { echo "?page=" . $previousPage; } ?>">Previous</a>
		</li>
		<?php for($i = 1; $i <= $lastPage; $i++ ): ?>
		<li class="page-item <?php if($currentPage == $i) {echo 'active'; } ?>">
			<a class="page-link" href="?page=<?= $i; ?>"> <?= $i; ?> </a>
		</li>
		<?php endfor; ?>
		<li class="page-item <?php if($currentPage >= $lastPage) { echo 'disabled'; } ?>">
			<a class="page-link"
			href="<?php if($currentPage >= $lastPage){ echo '#'; } else {echo "?page=". $nextPage; } ?>">Next</a>
		</li>
	</ul>
</nav>
import { Pagination } from "antd";

const [currentPage, setCurrentPage] = useState(1);
  const [itemPerPage, setItemPerPage] = useState(25);

const indexOfLastItem = currentPage * itemPerPage;
  const indexOfFirstItem = indexOfLastItem - itemPerPage;
  const currentItem = users.slice(indexOfFirstItem, indexOfLastItem);

//IMP. NOTE {(curretitem.map)map also run by curretitem}

    <Pagination
                total={users.length}
                current={currentPage}
                pageSize={itemPerPage}
                onChange={(currentPage) => setCurrentPage(currentPage)}
              />



// place the codes in functions.php and call the function wherever you want.

function philosophy_pagination()
{
   global $wp_query;
   $links = paginate_links(array(
      'current'      => max(1, get_query_var('paged')),
      'total'        => $wp_query->max_num_pages,
      'type'         => 'list',
      'mid_size'     => 3,
   ));
   $links = str_replace('page-numbers', 'pgn__num', $links);
   $links = str_replace("<ul class='pgn__num'>", "<ul>", $links);
   $links = str_replace('next pgn__num', 'pgn__next', $links);
   $links = str_replace('prev pgn__num', 'pgn__prev', $links);
   echo wp_kses_post($links);
}
star

Mon Aug 28 2023 21:14:16 GMT+0000 (Coordinated Universal Time)

#javascript #pagination #array #of #arrays
star

Thu Feb 16 2023 05:30:40 GMT+0000 (Coordinated Universal Time) https://stackoverflow.com/questions/48305624/how-to-use-mongodb-aggregation-for-pagination

#aggregation #mongodb #pagination
star

Sat Jan 21 2023 07:23:21 GMT+0000 (Coordinated Universal Time) https://codingstatus.com/how-to-create-pagination-in-php-mysql/

#pagination #corephp
star

Thu Oct 27 2022 12:40:10 GMT+0000 (Coordinated Universal Time) https://www.youtube.com/watch?v=kM73pwJpT1M

#react #antd #pagination
star

Tue May 31 2022 14:49:26 GMT+0000 (Coordinated Universal Time) https://wordpress.stackexchange.com/questions/53194/wordpress-paginate-wpdb-get-results

#wordpress #wpdb #pagination #php
star

Sat May 14 2022 10:38:29 GMT+0000 (Coordinated Universal Time)

#pagination #function

Save snippets that work with our extensions

Available in the Chrome Web Store Get Firefox Add-on Get VS Code extension