How to Add An Active Class to PHP Pagination

preview_player
Показать описание
How to Add An Active Class to PHP Pagination
Рекомендации по теме
Комментарии
Автор

After working with your code in the previous two videos then adding the active class as you showed in this video, I noticed an error that occurs. When the page first loads and there is no get variable in the url you get this error: Warning: Undefined array key "page".
I fixed it by doing this:
for($page=1; $page<=$number_of_pages; $page++){
if (isset ($_GET['page'])) {
if ($_GET['page'] == $page) {
$active ="active";
} else{
$active ="";
}
}

if (isset($active)) {
echo '<a class="'.$active.'" >'.$page.'</a>';
}else{
echo '<a >'.$page.'</a>';
}}

Not sure if this is the best way as I am just learning php and coding, I would be very interested to see how you would do it. Or have I missed something?

photoinshot