kayz100 Posted March 10, 2014 Share Posted March 10, 2014 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>'; } ?> Quote Link to comment Share on other sites More sharing options...
jairathnem Posted March 10, 2014 Share Posted March 10, 2014 in the URL what value is set for 'page'? Quote Link to comment Share on other sites More sharing options...
kayz100 Posted March 11, 2014 Author Share Posted March 11, 2014 the value in url is about.php Quote Link to comment Share on other sites More sharing options...
jairathnem Posted March 11, 2014 Share Posted March 11, 2014 is your URL something like this - about.php?page=somevalue ? if not, it should be like that cause you are accessing the page value in your page. read up on GET and POST requests. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.