0

我目前正在网站上工作,它有一个搜索框来搜索特定项目。该页面以表格格式回显结果。到目前为止一切正常,但是当我尝试过滤结果(取决于功能)时,我得到了两组结果。一个是之前显示的结果表,另一个是过滤后的结果。我不希望以前的结果在不影响任何其他程序的情况下再次显示在屏幕上。像会话之类的东西?我不知道如何处理这种情况。

<?php

include'search.php';// form for a search box. 


         if (isset($_POST['search_name']))  {
$search_name=mysql_real_escape_string(htmlentities(trim($_POST['search_name'])));
$errors = array();

if (empty($search_name)){

    $errors[] ='please enter a search term';
    }
else if (strlen($search_name)<3){
    $errors[] = 'your search term must be three or more characters'; 
    }
else if (1==2){
    $errors[] ='your search for '.$search_name.' returened no results';
    }
if (empty($errors)){



   filter($search_name); //it display another form in the navigation bar to filter the search result.


   search_results($search_name);//searches for all the result onthe database depending on the keyword  entered in searchbox. 


    } else{

    foreach($errors as $error)  {
        echo $error,'</br>';
        }
    }

}

?>
4

1 回答 1

1

请参阅此代码:

echo 'world';
echo 'hello !';

ob_start()您可以使用和截取ob_get_contents()回声ob_clean()

ob_start();
echo 'world';

var $echoed = ob_get_contents();
ob_clean();

// real echo
echo 'hello ' . $echoed . '!';

// now you see
// hello world!

因为 ob 的“输出缓冲”是 PHP 原生的,所以您可以将它与函数、包含等任何内容一起使用。我正在使用这种方法来拦截(1.)我的控制器流中的输出,并拦截(2.)视图的输出,因此我可以稍后组合它们(例如将 PHP 错误呈现到调试 div 中。

于 2013-03-10T16:56:40.917 回答