Jump to content

PHP Pagination without MYSQL


kayz100

Recommended Posts

Hi guys, thanks for all your help. I am trying to use php pagination without mysqli on one of my pages and I have the following php script. however, it keeps outputting an error that $page is not indexed please help and also how to put a css style attribute to my arrays.

 
<?php
$array = array('Music and chairs','hello mama','c','d','e','f','g','h','i','j'); //failing to put styles on this info array
$total_data = count($array); // COUNTING TOTAL ARRAY
$per_page = 3;
// Outputting error on the $page below
$page = intval($_GET['page']); // Error output is this - Undefined index: page


if(empty($page) || $page==1) {
$start_val = 0;
$end_val = $per_page - 1;
}
else {
$start_val = ($page * $per_page) - $per_page;
$end_val = $start_val + ($per_page - 1);
}


//Echoing my array and failing to use my css
for($i=$start_val;$i<=$end_val;$i++){ 
echo $array[$i].' ';
}


$less_than = $total_data/$per_page;
if($less_than>intval($less_than)) $less_than = $less_than + 1;


if($total_data>1) {
echo '<div class="pagination">';
echo ($page-1)>0?'<a href="?page='.($page-1).'">Previous</a> ':'Previous ';
for($i=1;$i<=$less_than;$i++){
if($page==$i) echo '<a class="paginator linkno">';
else echo '<a href="?page='.$i.'" class="paginator">';
echo $i;
echo '</a> ';
}
echo ($page+1)<=$less_than?'<a href="?page='.($page+1).'">Next</a>':'Next';
echo '</div>';
}
?>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.