$page = min($page, $numPages); $offset = ($page - 1) * $limit; $ret = new stdClass(); $ret->offset = $offset; $ret->limit = $limit; $ret->numPages = $numPages; $ret->page = $page; return $ret; } } $page = $_GET['page']; $limit = 7; $result = mysql_query("select count(*) from news"); $total = mysql_result($result, 0, 0); // work out the pager values $pager = Pager::getPagerData($total, $limit, $page); $offset = $pager->offset; $limit = $pager->limit; $page = $pager->page; // use pager values to fetch data $is_published = "1"; $query = "select * from news WHERE is_published = '{$is_published}' order by id desc limit {$offset}, {$limit}"; $result = mysql_query($query); //check if the id is set if ($result == "") { ?> <p> No News </p> <?php } else { while ($row = mysql_fetch_array($result, MYSQL_ASSOC)) { ?>
function showPaging($query, $res_set, $PageURL) { global $db; $page = $_REQUEST['page']; $limit = 20; $sql = $query; $totalcom = count($res_set); $total = $totalcom; $pager = Pager::getPagerData($total, $limit, $page); $offset = $pager->offset; $limit = $pager->limit; $page = $pager->page; $sql .= " limit {$offset},{$limit}"; $res_page = $db->select_data($sql); $total_com = count($res_page); Pager::getPaging_pagenum($PageURL, $page, $pager->numPages, $pager->limit); return $res_page; }