Category Paging, Set apart to two Functions

Hi;
I have wrote a function that fetch articles belongs to category id with url query.


function cat_paging()
{
    $cid = get_url();
    $perPage = 6;
    $current_page = $_SERVER["PHP_SELF"];
    $page = is_numeric($_GET["page"]) ? $_GET["page"] : 1;
    //$start = ($page * $perPage) - $perPage;
    if ($page)
        $start = ($page - 1) * $perPage;
    else
        $start = 0;
    $sql = sprintf("SELECT id, title, abstract, content_image FROM content WHERE catID = %d ORDER BY id DESC LIMIT %d, %d",
        $cid, $start, $perPage);
    $news_array_paging = table_to_array($sql);
    foreach ($news_array_paging as $key => $value) {
        $txt = '<ul class="contentPaging">
            <li>
                <img src="images/' . $value['content_image'] .
            '" width="100" height="100">
                <h2>' . $value['title'] . '</h2>
                <a href="news.php?contID=' . $value['id'] . '">' . $value['abstract'] .
            ' <span>Read More...</span></a>
                 
            </li>
        </ul>';
        echo $txt;
    }


    $totalCount = sprintf("SELECT COUNT(*) as 'Total' FROM content WHERE catID = %d",
        $cid);
    $count = mysql_query($totalCount);
    $rowCount = mysql_fetch_array($count);
    $totalRow = $rowCount['Total'];
    $totalPage = ceil($totalRow / $perPage);
    $prev = $page - 1;
    $next = $page + 1;

    $paging = '<ul class="paging">';
    if ($page > 1) {
        $paging .= '<li><a href="' . $current_page . '?cID=' . $cid . '&page=' . $prev .
            '">&#214;nceki</a></li>';
    }

    for ($i = 0; $i < $totalPage; $i++) {
        $j = $i + 1;
        $prev = $j - 1;


        if ($_GET['page'] == $j) {
            $class = "pCurrent";
        } else {
            $class = "";
        }
        $paging .= '<li><a href="' . $current_page . '?cID=' . $cid . '&page=' . $j .
            '" class="' . $class . '">' . $j . '</a></li>';
    }
    if ($page < $totalPage) {
        $paging .= '<li><a href="' . $current_page . '?cID=' . $cid . '&page=' . $next .
            '">Sonraki</a></li>';
    }
    $paging .= '</ul>';

    return $paging;

}

This function works perfect but I want to set apart paging section. In this way, I have to use urlquery twice:

function get_url()
{
    global $cid;
    if (is_numeric($_GET['cID'])) {
        $cid = $_GET['cID'];
    }
    return $cid;
}

How can I do this with avoid twice url query?
Thanks in advance

But I want to set apart paging from content fetching.

news.php?cID=...
content.php?contID=...
gallery.php?galID=...

I want to use only one paging function with different ulr queries.
I think that this is not possible and I have to write paging codes inside database content fetching function.

@pmw57
Thanks for help and great functions.
:beer:

Using the filter_input function with an appropriate [url=“http://www.php.net/manual/en/filter.filters.php”]filter is a good way these days.

function get_url()
{
    global $cid;
    $getcid = filter_input(INPUT_GET, 'cID', FILTER_VALIDATE_INT);
    if ($getcid !== FALSE) {
        $cid = $getcid;
    }
    return $cid;
}