PHP中的{paginate_middle} Smarty分页无法正常工作

时间:2014-08-02 20:12:54

标签: php pagination smarty

我正在使用聪明的分页我的分页URL看起来像这样

categories.php?id=1&next=3

现在{paginate_prev}& {paginate_next}正常运行 但{paginate_middle}正在剥离ID参数,它正在生成这样的URL

categories.php?next=3

我的分页代码在这里

function get_db_results() {
    global $conn;
    $id = htmlspecialchars((int)$_GET['id']);
  if ($id){
  $_query = sprintf('SELECT SQL_CALC_FOUND_ROWS * FROM newser where idblog = '.$conn->qstr($id).' and (main = '.$conn->qstr('0').' or main = '.$conn->qstr('2').')  ORDER BY blogid DESC LIMIT %d,%d',
        SmartyPaginate::getCurrentIndex(),SmartyPaginate::getLimit());
    }
    else
    {
    $_query = sprintf('SELECT SQL_CALC_FOUND_ROWS * FROM newser where (main = '.$conn->qstr('0').' or main = '.$conn->qstr('2').') ORDER BY blogid DESC LIMIT %d,%d',
        SmartyPaginate::getCurrentIndex(),SmartyPaginate::getLimit());
    }

        $brecordSet = $conn->Execute($_query);
        if(!$brecordSet)
            print $conn->ErrorMsg();
        else
            while(!$brecordSet->EOF) {
                $_data[] = $brecordSet->GetRowAssoc(false);
                $brecordSet->MoveNext();
            }
        $_query = "SELECT FOUND_ROWS() as total";
        $crecordSet = $conn->Execute($_query);
        if(!$crecordSet)
            print $conn->ErrorMsg();
        else
            $_row = $crecordSet->GetRowAssoc();
        $total = $crecordSet->fields['total'];
        SmartyPaginate::setTotal($total);
        return @$_data;
        $brecordSet->Close();
        $crecordSet->Close();
    }
    require ('libs/SmartyPaginate.class.php');
    SmartyPaginate::connect();
    SmartyPaginate::setLimit(4);
    SmartyPaginate::setUrl('categories.php');
    $smarty->caching = $caching;
    $smarty->assign('results',get_db_results());
    SmartyPaginate::assign($smarty);
    $id = htmlspecialchars((int)$_REQUEST['id']);
    @$next = htmlspecialchars((int)$_REQUEST['next']);
    $cid = $id.$next;
    $smarty->display('categories.php',$cid);

请帮助我理解我的代码是否有任何问题,或者是smarty {paginate_middle}的错误,该错误不是多个参数

1 个答案:

答案 0 :(得分:0)

我根本不使用SmartyPaginate,但似乎你应该改变这一行:

SmartyPaginate::setUrl('categories.php');

SmartyPaginate::setUrl('categories.php?id=1');