PHP pagination results per page?

Hi, I can’t make this work. I got the pagination part done but the problem is that it shows the same content on all pages. I mean how to split the content so that half will show on one page and the rest on the other?

$querycount = $db->query("
        SELECT COUNT(t.tid) AS total
        FROM ".TABLE_PREFIX."threads t
        WHERE t.fid = 001
        ");
$total = $db->fetch_field($querycount, "total");

$pagina = intval($mybb->input['page']);
    $perpage = 1;
    if($pagina > 0)
    {
        $start = ($pagina - 1) * $perpage;
        $pages = $total / $perpage;
        $pages = ceil($pages);
        if($pagina > $pages || $pagina <= 0)
        {
            $start = 0;
            $pagina = 1;
        }
    }
    else
    {
        $start = 0;
        $pagina = 1;
    }
$pageurl = $mybb->settings['bburl'] . "/news.php";
$pagination = multipage($total, (int)$perpage, (int)$pagina, $pageurl);

P.S. Here is the main query that fetches results!

$query = $db->query("
        SELECT p.message, p.dateline, p.uid, p.username, u.avatar
        FROM ".TABLE_PREFIX."posts p
        LEFT JOIN ".TABLE_PREFIX."forums f ON (p.fid = f.fid)
        LEFT JOIN ".TABLE_PREFIX."users u ON (p.uid=u.uid)
        WHERE f.fid = 001
        ORDER BY p.dateline DESC 
        ");

You need to add a LIMIT to your main query with the start and per-page values. You don’t want to retrieve all rows from the database but only those to be shown on the current page.

Sorry for the late reply but you right works great.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.