无法弄清楚如何获得多个搜索变量的结果

时间:2015-03-06 01:50:28

标签: php pdo

我在分页页面的搜索结果的最后一步。我已经完成了所有工作,但只有当搜索输入文本字段有。我需要它能够为search_text接收多个值,因为会有几个搜索选项。也就是说,如何将$ pagination传递给值并按照下面的说明完成它的工作?页面上HTML表单上的所有表单输入类型都具有名称search_text。

我在之前的搜索代码中没有分页,我将多个搜索查询选项放入search.php,如下所示:

//the HTML form from another page that is sending the two values
<form name="search" method="post" 
action="http://example.com/search"> Seach for: <input type="text" 
name="search_text[]" /> 
<select name="search_text[]">
<option value="Fiction" selected>Comedy</option>
<option value="Non-Fiction">Drama</option>
</select>
<input type="submit" name="search_button" value="search" /></form>


//search queries from multiple select/input fields in form 
$input = array(
"search_text" => $_REQUEST['search_text'],);
$sgenre = $input['search_text'][0];
$scategory = $input['search_text'][1];

现在我需要弄清楚如何改变下面的代码(这是有效的,但只有当html表单只有一个名为search_text的输入文本框时。我怎样才能使下面的代码接受我带到的多个值上面代码的页面?

$query = "SELECT * FROM stories";
if(isset($_REQUEST["search_text"]) && $_REQUEST["search_text"] != "")
{
$search = htmlspecialchars($_REQUEST["search_text"]);
$pagination->param = "&search=$search";
$query .= " WHERE stories.genre LIKE '%$search%'";
}
$pagination->rowCount($query);
$pagination->config(3, 5);
$query .= " ORDER BY SID ASC LIMIT {$pagination->start_row}, 
{$pagination->max_rows}";

1 个答案:

答案 0 :(得分:0)

也许是这样的

$query = "SELECT * FROM stories";
if(isset($_REQUEST["search_text"]) && $_REQUEST["search_text"] != "")
{

$search = htmlspecialchars($_REQUEST["search_text"]);

$genre =  htmlspecialchars($_REQUEST["search_text"][0]);
$category = htmlspecialchars($_REQUEST["search_text"][1]);

$pagination->param = "&search=$search";

$query .= " WHERE stories.genre LIKE '%$search%'";
$query .= " AND stores.genre LIKE '%$category'";

}