【问题标题】:Paging and edit category status分页和编辑类别状态
【发布时间】:2010-04-04 17:15:16
【问题描述】:

对于编辑类别的主页状态,我有一个链接:

<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>

和功能:

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

一切正常,但有分页:

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

我希望将位于 pg=2 中的项目重定向到 index.php?page=categories&pg=2 我怎样才能做到这一点?提前致谢

分页功能:

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

【问题讨论】:

    标签: php


    【解决方案1】:

    我认为您需要做的是获取 pg 变量并将其添加到重定向中。在您的 header 命令之前添加以下行。 (is_numeric() 检查是为了安全。)

     if (is_numeric($_GET["pg"]))
      $page = "&pg=".$_GET["pg"];
     else
      $page = null; 
    
     header("Location: index.php?page=categories$page");
    

    旧答案:

    您在寻找分页解决方案吗? SO已经有一些了。相关问题:

    More on SO

    【讨论】:

    • 嗨佩卡;我的脚本中有分页。示例:我在 p-numbmer = 2:index.php?page=categories&pg=2 我想激活此页面中的项目:Active 我想在“更新”后返回 index.php?page=categories&pg=2 (动态相同的页面)。我必须编辑标题位置。我该怎么做
    • 它已经重定向到 index.php?page=categories :(
    • @jasmine 对不起,我犯了愚蠢的错误。再试一次,我把header中的单引号换成了双引号。
    • 试试:header('Location: index.php?page=categories' . $page);
    • $page 始终设置为 null,如下所示: function homepstatus() { if (is_numeric($_GET["pg"])) $page = "&pg=".$_GET["pg" ];否则 $page = null; $ID = mysql_real_escape_string($_GET['id']); $query = "更新类别 SET home = 1 WHERE id='$ID'"; $result = mysql_query($query); if (mysql_affected_rows () == 1) { header('Location: index.php?page=categories' . $page); } } 它被重定向到 index.php?page=categories
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-02-10
    • 2021-06-24
    • 1970-01-01
    • 2015-04-28
    • 2019-08-03
    相关资源
    最近更新 更多