0

For edit home status of category I have a link:

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

and function:

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');
      }
 }

Everything works fine but there is paging :

/index.php?page=categories&pg=2

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

paging function:

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 > 1)
{   
    $pagination .= "<div class='pagination'>";
if ($pg > 1)
    $pagination.= "<a href='".$path."pg=$prev' class=\"prev\">« Önecki</a>";
else
    $pagination.= "<span class='disabled'>« Önceki</span>";   

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

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


return $pagination;
}

1 Answers1

0

I think what you need to do is get the pg variable and add it to the redirect. Add the following lines before your header command. (The is_numeric() check is for security.)

 if (is_numeric($_GET["pg"]))
  $page = "&pg=".$_GET["pg"];
 else
  $page = null; 

 header("Location: index.php?page=categories$page");

Old answer:

Are you looking for pagination solutions? There are a few on SO already. Related questions:

More on SO

Community
  • 1
  • 1
Pekka
  • 418,526
  • 129
  • 929
  • 1,058
  • Hi pekka; I have pagination in my script. Expamle: Im in p-numbmer = 2: index.php?page=categories&pg=2 I want to active an item that is in this page: Active I want after "updating" returns to index.php?page=categories&pg=2 (the same page dynamically). I have to edit header location. How can I do this –  Apr 03 '10 at 19:25
  • Its redirected to index.php?page=categories yet :( –  Apr 03 '10 at 19:42
  • @jasmine sorry, stupid mistake on my end. Try again, I replaced the single quotes in `header` by double ones. – Pekka Apr 03 '10 at 19:46
  • Try: `header('Location: index.php?page=categories' . $page);` – Decent Dabbler Apr 03 '10 at 19:46
  • $page always sets to null, with this: function homepstatus() { if (is_numeric($_GET["pg"])) $page = "&pg=".$_GET["pg"]; else $page = null; $ID = mysql_real_escape_string($_GET['id']); $query = "UPDATE category SET home = 1 WHERE id='$ID' "; $result = mysql_query($query); if (mysql_affected_rows () == 1) { header('Location: index.php?page=categories' . $page); } } Its redirected to index.php?page=categories –  Apr 03 '10 at 19:53
  • What is the URL this is happening in? Can you show an exact URL? – Pekka Apr 03 '10 at 19:54
  • @jasmine where would `pg` come from in that case? If it's not in the URL, there is no way for the script to tell what page it's on. Is `pg` available in the page where you have the initial "active" link? If yes, then you need to build it in there as well. What are you using there, Smarty? – Pekka Apr 03 '10 at 20:01
  • Its Raw php, no smarty o template engine used. I have updated my question. pg comes from pagination function –  Apr 03 '10 at 20:02
  • @jasmine then you need to put `pg` in there somehow: `?page=homestatus&id={$row['id']}{$page}` use the first 4 lines from my code example above to fill the current page into `$page`. That requires that the page you're in has the `pg` variable set in its URL. – Pekka Apr 03 '10 at 20:06
  • Thank you, I will try this way. –  Apr 03 '10 at 20:09