php分页,每页限制

Anyone can help me with this code to limit number per page,

function PageMain() {
    global $TMPL;

    $text = $_GET['a'];
    $name = urldecode(htmlEntities($_GET['q']));
    // pagination
    $per_page = 10;
    $page_query = mysql_query("SELECT COUNT(genres) from table WHERE genres LIKE '%%$name%'");
    $pages = @ceil(mysql_result($page_query, 0) / $per_page);

    $page = (isset($_GET['page']) AND (int)$_GET['page'] > 0) ? (int)$_GET['page'] : 1;
    $start = ($page - 1) * $per_page;

    $skin = new skin('shared/pagination'); $pagination = '';
    if ($pages >= 1 && $page <= $pages) {   
        for ($x=1; $x<=$pages; $x++) {
            $TMPL['pagination'] = ($x == $page) ? '<a class="active" href="/index.php?a=genre&q='.urlencode($name).'&page='.$x.'">'.$x.'</a> ' : '<a href="/index.php?a=genre&q='.urlencode($name).'&page='.$x.'">'.$x.'</a> ';
                $pagination .= $skin->make();
            }
        }
    $TMPL['pagination'] = $pagination;
}

now looks like on this picture:

http://i.imgur.com/7Y0tF.png

I need to make something like this, with next and last page:

http://i.imgur.com/7Oqfn.gif

For large numbers of pages, consider using "logarithmic" pagination, see here:

How to do page navigation for many, many pages? Logarithmic page navigation