Pagination Not Works Fine.. It Counts Whole Not According to Category

135
March 31, 2018, at 5:34 PM
<?php
    include"admin/config.php";
//pagination function
function pagination($query,$per_page=10,$page=1,$url='?'){   
    global $conn; 
    $query = "SELECT COUNT(*) as `num` FROM {$query}";
    $row = mysqli_fetch_array(mysqli_query($conn,$query));
    $total = $row['num'];
    $adjacents = "2"; 
    $prevlabel = "&lsaquo; Prev";
    $nextlabel = "Next &rsaquo;";
    $lastlabel = "Last &rsaquo;&rsaquo;";
    $page = ($page == 0 ? 1 : $page);  
    $start = ($page - 1) * $per_page;                               
    $prev = $page - 1;                          
    $next = $page + 1;
    $lastpage = ceil($total/$per_page);
    $lpm1 = $lastpage - 1; // //last page minus 1
    $pagination = "";
    if($lastpage > 1){   
        $pagination .= "<ul class='pagination'>";
        $pagination .= "<li class='page_info'>Page {$page} of {$lastpage}</li>";
            if ($page > 1) $pagination.= "<li><a class='frist' href='{$url}page={$prev}'>{$prevlabel}</a></li>";
        if ($lastpage < 7 + ($adjacents * 2)){   
            for ($counter = 1; $counter <= $lastpage; $counter++){
                if ($counter == $page)
                    $pagination.= "<li><a class='current'>{$counter}</a></li>";
                else
                    $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>";                    
            }
        } elseif($lastpage > 5 + ($adjacents * 2)){
            if($page < 1 + ($adjacents * 2)) {
                for ($counter = 1; $counter < 4 + ($adjacents * 2); $counter++){
                    if ($counter == $page)
                        $pagination.= "<li><a class='first'>{$counter}</a></li>";
                    else
                        $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>";                    
                }
                $pagination.= "<li class='dot'>...</li>";
                $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a></li>";
                $pagination.= "<li><a href='{$url}page={$lastpage}'>{$lastpage}</a></li>";  
            } elseif($lastpage - ($adjacents * 2) > $page && $page > ($adjacents * 2)) {
                $pagination.= "<li><a href='{$url}page=1'>1</a></li>";
                $pagination.= "<li><a href='{$url}page=2'>2</a></li>";
                $pagination.= "<li class='dot'>...</li>";
                for ($counter = $page - $adjacents; $counter <= $page + $adjacents; $counter++) {
                    if ($counter == $page)
                        $pagination.= "<li><a class='current'>{$counter}</a></li>";
                    else
                        $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>";                    
                }
                $pagination.= "<li class='dot'>..</li>";
                $pagination.= "<li><a href='{$url}page={$lpm1}'>{$lpm1}</a></li>";
                $pagination.= "<li><a href='{$url}page={$lastpage}'>{$lastpage}</a></li>";      
            } else {
                $pagination.= "<li><a href='{$url}page=1'>1</a></li>";
                $pagination.= "<li><a href='{$url}page=2'>2</a></li>";
                $pagination.= "<li class='dot'>..</li>";
                for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter <= $lastpage; $counter++) {
                    if ($counter == $page)
                        $pagination.= "<li><a class='current'>{$counter}</a></li>";
                    else
                        $pagination.= "<li><a href='{$url}page={$counter}'>{$counter}</a></li>";                    
                }
            }
        }
            if ($page < $counter - 1) {
                $pagination.= "<li><a class='last' href='{$url}page={$next}'>{$nextlabel}</a></li>";
                $pagination.= "<li><a class='last' href='{$url}page=$lastpage'>{$lastlabel}</a></li>";
            }
        $pagination.= "</ul>";        
    }
    return $pagination;
}
?>

Pagination works fine but problem is it count whole pages on every page if on one page there is 20 post so on first page

i want pagination works according to categorey ..

table structure
Mytable
       vidtable
                Eng
(Eng is category row)

problem comes on website https://torrentgang.com/Hollywood.html

Please Help

READ ALSO
this query shows #1248 - Every derived table must have its own alias

this query shows #1248 - Every derived table must have its own alias

You have a left join ( subselect ) without an alias add (eg:) T at the end of the subquery ()

116
Update a table such that multiple users get a new row

Update a table such that multiple users get a new row

Let's say I have a table called grades that has this:

116
How to put my database schema (.mwb) on mysql server on ubuntu?

How to put my database schema (.mwb) on mysql server on ubuntu?

I have a my sql server running on my ubuntu 1604 server and created on my local mysql workbench a new database schema (

160
Not all parameters used the sql statement python mysql

Not all parameters used the sql statement python mysql

I'm receiving an Internal Error Unread result foundHere is the error in details

542