I've been trying a lot of ways to add PHP pagination. I have tried searching and trying to figure other ways of implementing the pagination but none of them work.
Here's how I created the Index page:
<?php
$menuItems = array(
"post1" => array(
"title" => "Sample Title",
"utime" => "M/d/Y",
"content" => "<p>Body of the post</p>"
),
"post2" => array(
"title" => "Another Sample Title",
"utime" => "M/d/Y",
"content" => "<p>Content goes here...</p>"
),
);
foreach ($menuItems as $contItem => $item) {
?>
<li>
<a href="dish.php?item=<?php echo $contItem; ?>">
<h1><?php echo $item["title"]; ?></h1>
<small><?php echo $item["utime"]; ?></small>
</a>
</li>
<?php } ?>
I would like to know how I can paginate the the array list. Thanks!
u can use simple PHP function called array_slice()
show first 10 items.
show next 10 items.
UPDATE:
UPDATE#2:
Example of pagination:
Another viable option is to use
array_chunk()
: