Php 在使用分页链接时保留POST中的数组

Php 在使用分页链接时保留POST中的数组,php,post,if-statement,pagination,Php,Post,If Statement,Pagination,我的搜索引擎有点问题。 它输出的搜索结果很好,但是当我单击分页链接时,它失败了,当然,因为它不再具有$\u POST数组。我正在使用这段代码: if(empty($_POST) == false) { $res = $search->search_ads($_POST); if($res == false) { $view->setData('numres', 0); } else { $view->setData('n

我的搜索引擎有点问题。 它输出的搜索结果很好,但是当我单击分页链接时,它失败了,当然,因为它不再具有
$\u POST
数组。我正在使用这段代码:

if(empty($_POST) == false) {

    $res = $search->search_ads($_POST);

    if($res == false) {
       $view->setData('numres', 0);
    } else {
        $view->setData('numres',$res[2]);
        $view->setData('adverts', $res[0]);
   }

   $app->view()->setData('paginate', $res[1]);
   $app->render('search.tpl');
} else {
   $app->render('404.tpl');
}
当我点击f.x.“第2页”时,它将呈现404模板

有没有办法保留
$\u POST
数组,并在
搜索广告
功能中重用它

“paginate”包含分页的HTML

<li><a class=\"paginate\" href=\"$target?page=$next_page&ipp=$this->items_per_page\">«</a></li>":"<li><span class=\"inactive\" href=\"#\">«</span></li>
  • ”:“

  • 将post数组存储在变量中,然后在其他地方使用它

    $post_array = $_POST;
    $res = $search->search_ads($post_array);
    
    使用会话

    session_start(); //on the top of your php file.
    ...
    
    if(!empty($_POST))
       $_SESSION['post_data']= $_POST;
    ...
    
    if(empty($_SESSION['post_data']) == false) {
    $res = $search->search_ads($_SESSION['post_data']);
    ...
    
    }
    

    您希望在后续页面上检查$\u GET而不是$\u POST,因为这是您传递数据的方法:

    href=\"$target?page=$next_page&ipp=$this->items_per_page\"
    
    将为您提供包含键值对的$\u GET数组:

    $_GET['page'] = value of $next_page 
    $_GET['ipp']  = value of $this->items_per_page