All pastes #106413 Raw Edit

Unnamed

public php v1 · immutable
#106413 ·published 2006-07-30 08:35 UTC
rendered paste body
<?// how many rows to show per page$rowsPerPage = 5;// by default we show first page$pageNum = 1;// if $_GET['page'] defined, use it as page numberif(isset($_GET['page']))$pageNum = $_GET['page'];// counting the offset$offset = ($pageNum - 1) * $rowsPerPage;$query  = "SELECT id FROM tags LIMIT $offset, $rowsPerPage";$result = db_query($query);// print out the tagswhile($row = db_array($result)){    echo $row['id'] . '<br>';}echo '<br>';// how many rows we have in database$query   = "SELECT COUNT(id) AS numrows FROM tags WHERE user_id = '".ID."'";$result  = db_query($query);$row     = db_array($result);$numrows = $row['numrows'];// how many pages we have when using paging?$maxPage = ceil($numrows/$rowsPerPage);// print the link to access each page$self = $_SERVER['PHP_SELF'];$nav = '';$pagetabs = 5;$serparator = '<span class="disabled">...</span>';if ($pageNum <= 3){$page = 1;}if ($pageNum = 4){$page = $pageNum-2;$pagetabs = $pagetabs + 1;}if ($pageNum > 4){$page = $pageNum-2;$pagetabs = $pagetabs + 2;}if ($pageNum == $maxPage){$page = $maxPage-5;}echo $page;echo '-'.$pagetabs;for($page; $page <= $pagetabs; $page++){     if ($page == $pageNum)    {        $nav .= '<span class="disabled">'.$page.'</span>';   // no need to create a link to current page        }else{        if ($page <= 3)        {            $nav .= '<a href="'.$self.'?page='.$page.'">'.$page.'</a>';        }        if ($page >= 4)        {            $nav .= '<a href="'.$self.'?page='.$page.'">'.$page.'</a>';        }    }} // creating previous and next link// plus the link to go straight to// the first and last pageif ($pageNum > 1){    $page = $pageNum - 1;    $prev = ' <a href="'.$self.'?page='.$page.'">&laquo; Previous</a> ';        //$first = '<a href="'.$self.'?page=1">[First Page]</a>';} else{    $prev  = '<span class="disabled">&laquo; Previous</span>'; // we're on page one, don't print previous link    //$first = '&nbsp;'; // nor the first page link}if ($pageNum < $maxPage){    $page = $pageNum + 1;    $next = ' <a href="'.$self.'?page='.$page.'">Next &raquo;</a> ';        //$last = " <a href="'.$self.'?page=$maxPage">[Last Page]</a> ";} else{    $next = ' <span class="disabled">Next &raquo;</span>'; // we're on the last page, don't print next link    //$last = '&nbsp;'; // nor the last page link}// print the navigation linkecho '<div class="pages">'. $prev . $nav . $next . $last.'</div>'; ?>