Paging and edit category status
<p>For edit home status of category I have a link:</p>

<pre><code>&lt;span class=\"ha\" title=\"Active in Homepage\"&gt;Active in Homepage&lt;/span&gt;&lt;a href=\"?page=homestatus&amp;id={$row['id']}\" class=\"hp\"  title=\"\"&gt;Passive in home page&lt;/a&gt;
</code></pre>

<p>and function:</p>

<pre><code>function homestatus() {
  $ID     = mysql_real_escape_string($_GET['id']);
  $query  = "UPDATE category SET home = 0  WHERE id= $ID ";
  $result = mysql_query($query);
    if (mysql_affected_rows () == 1) {
       header('Location: index.php?page=categories');
      }
 }
</code></pre>

<p>Everything works fine but there is paging :</p>

<pre><code>/index.php?page=categories&amp;pg=2
</code></pre>

<p>I want that an item located in pg=2, redirected to index.php?page=categories&amp;pg=2
How can I do this? Thanks in advance</p>

<p>paging function:</p>

<pre><code>function Pages($tbl_name,$limit,$path){

$query = "SELECT COUNT(*) as num FROM $tbl_name";
$total_pages = mysql_fetch_array(mysql_query($query));
$total_pages = $total_pages[num];
$adjacents = "2";
$pg = $_GET['pg'];
if($pg)
    $start = ($pg - 1) * $limit;
else
    $start = 0;

$sql = "SELECT id FROM $tbl_name LIMIT $start, $limit";
$result = mysql_query($sql);

if ($pg == 0) $pg = 1;
    $prev = $pg - 1;
    $next = $pg + 1;
    $lastpage = ceil($total_pages/$limit);
    $lpm1 = $lastpage - 1;

    $pagination = "";
if($lastpage &gt; 1)
{   
    $pagination .= "&lt;div class='pagination'&gt;";
if ($pg &gt; 1)
    $pagination.= "&lt;a href='".$path."pg=$prev' class=\"prev\"&gt;« Önecki&lt;/a&gt;";
else
    $pagination.= "&lt;span class='disabled'&gt;« Önceki&lt;/span&gt;";   

if ($lastpage &lt; 7 + ($adjacents * 2))
{   
for ($counter = 1; $counter &lt;= $lastpage; $counter++)
{
if ($counter == $pg)
    $pagination.= "&lt;span class='current'&gt;$counter&lt;/span&gt;";
else
    $pagination.= "&lt;a href='".$path."pg=$counter'&gt;$counter&lt;/a&gt;";                   
}
}
elseif($lastpage &gt; 5 + ($adjacents * 2))
{
if($pg &lt; 1 + ($adjacents * 2))       
{
for ($counter = 1; $counter &lt; 4 + ($adjacents * 2); $counter++)
{
if ($counter == $pg)
    $pagination.= "&lt;span class='current'&gt;$counter&lt;/span&gt;";
else
    $pagination.= "&lt;a href='".$path."pg=$counter'&gt;$counter&lt;/a&gt;";                   
}
    $pagination.= "...";
    $pagination.= "&lt;a href='".$path."pg=$lpm1'&gt;$lpm1&lt;/a&gt;";
    $pagination.= "&lt;a href='".$path."pg=$lastpage'&gt;$lastpage&lt;/a&gt;";       
}
elseif($lastpage - ($adjacents * 2) &gt; $pg &amp;&amp; $pg &gt; ($adjacents * 2))
{
    $pagination.= "&lt;a href='".$path."pg=1'&gt;1&lt;/a&gt;";
    $pagination.= "&lt;a href='".$path."pg=2'&gt;2&lt;/a&gt;";
    $pagination.= "...";
for ($counter = $pg - $adjacents; $counter &lt;= $pg + $adjacents; $counter++)
{
if ($counter == $pg)
    $pagination.= "&lt;span class='current'&gt;$counter&lt;/span&gt;";
else
    $pagination.= "&lt;a href='".$path."pg=$counter'&gt;$counter&lt;/a&gt;";                   
}
    $pagination.= "..";
    $pagination.= "&lt;a href='".$path."pg=$lpm1'&gt;$lpm1&lt;/a&gt;";
    $pagination.= "&lt;a href='".$path."pg=$lastpage'&gt;$lastpage&lt;/a&gt;";       
}
else
{
    $pagination.= "&lt;a href='".$path."pg=1'&gt;1&lt;/a&gt;";
    $pagination.= "&lt;a href='".$path."pg=2'&gt;2&lt;/a&gt;";
    $pagination.= "..";
for ($counter = $lastpage - (2 + ($adjacents * 2)); $counter &lt;= $lastpage; $counter++)
{
if ($counter == $pg)
    $pagination.= "&lt;span class='current'&gt;$counter&lt;/span&gt;";
else
    $pagination.= "&lt;a href='".$path."pg=$counter'&gt;$counter&lt;/a&gt;";                   
}
}
}

if ($pg &lt; $counter - 1)
    $pagination.= "&lt;a href='".$path."pg=$next'&gt;Sonraki »&lt;/a&gt;";
else
    $pagination.= "&lt;span class='disabled'&gt;Sonraki »&lt;/span&gt;";
    $pagination.= "&lt;/div&gt;\n";       
}


return $pagination;
}
</code></pre>
