I'm working on a piece of code that does pagination for different sorting systems. It works for likes and outputs correctly, but does not work for the sorting system of tag.
$sorting = $_GET["sorting"];
$per_page = 10;
$pages = $count_total->num_rows;
$total_pages = ceil($pages / $per_page);
if($sorting == "likes") {
$count_total = $db2->query("SELECT * FROM likes WHERE user='$user'");
}
if($sorting == "tag") {
$tag_name = $_GET["tag_name"];
$count_total = $db2->query("SELECT * FROM movie_tags WHERE tag_id='$tag_name'");
}
$pages = $count_total->num_rows;
$total_pages = ceil($pages / $per_page);
$start = (($page - 1) * $per_page);
for($number=1;$number<=$total_pages;$number++) {
if($page == $number) {
echo '<div class="complete_page">'.$number.'</div>';
} else {
$sorting = $_GET["sorting"];
echo '<a href="?page='.$number.'&sorting='.$sorting.'"> <div class="number_page">'.$number.'</div></a>';
}
}
}
This is an example of how I'm using pagination:
$movie = $db2->query("SELECT * FROM movies ORDER BY likes DESC LIMIT $start, $per_page");
NOTE: When I echo $pages
, both sorting systems generate values. In fact, tag has a value of 11. Why is this value not creating the pagination system. I know this is not a problem with the pagination system because it is working for the sorting system of likes.