我已经创建了全文搜索,我希望结果显示在新页面上,在该页面上提供了按价格过滤的选项。
搜索有效,并且$ query =“ SELECT * FROM Property
WHERE MATCH(Name
,Property_Type
,Listing_Type
,Address
,City
, Description
)反对('%$ keyword%'在BOOLEAN模式下”)
在我按下按钮进行排序之后,查询不再使用$ keyword,而是仅使用$ sort一个:SELECT * FROM Property
WHERE MATCH(Name
,Property_Type
, Listing_Type
,Address
,City
,Description
)反对('%%'在BOOLEAN模式下)按价格ASC排序
所以它是一个或另一个。我需要帮助,以使查询的最新版本同时接收第一个变量和第二个变量。
帮助?
<form action="" method="POST">
<select name="sort" >
<option value=>Order By</option>
<option value=price_desc>Price descending</option>
<option value=price_asc>Price ascending</option>
<option value=date_asc>Most recent</option>
<input type="submit" name="sortingbtn" placeholder="Sort"/>
</select>
<?php
include('database_connection.php');
$keyword= $_POST['keyword'];
$query = "SELECT * FROM `Property` WHERE MATCH(`Name`,`Property_Type`,`Listing_Type`,`Address`,`City`,`Description`) Against('%$keyword%' IN BOOLEAN MODE)";
if(isset($_POST["sortingbtn"]))
{ $keyword= $_POST['keyword'];
$sort=$_POST['sort'];
if ($sort == 'price_desc')
{
$query .= " ORDER BY Price DESC";
}
else if ($sort == 'price_asc')
{
$query .= " ORDER BY PRICE ASC";
}
}
else
{
echo $output;
}
$statement = $connect->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$total_row = $statement->rowCount();
$output = '';
if($total_row > 0)
{
foreach($result as $row)
{
$output .= ' <div class="col-sm-4 col-lg-3 col-md-3">
<div style="border:1px solid #ccc; border-radius:5px; padding:10px; margin-bottom:16px; height:250px;">
<p align="center"><strong><a href="#">'. $row['Name'] .'</a></strong></p>
<h4 style="text-align:center;" class="text-danger" >'. $row['Price'] .'</h4>
<p>Property Type : '. $row['Property_Type'].' <br />
<p>For : '. $row['Listing_Type'].' <br />
<p>City : '. $row['City'].' <br />
</div>
</div>
';
}
}
else
{
$output = '<h3>No Data Found</h3>';
}
echo $output;
echo $query;
?>
<form method="POST" action="search_results.php">
<input type="search" name="keyword" placeholder="Enter here"/>
<input type="submit" name="searchbtn" placeholder="Search"/>
</form>
答案 0 :(得分:0)
在您的search_results.php
中,您可以通过在某些keyword
字段中为其分配值来获得input
,如下所示:
<form action="" method="POST">
<!-- hiddden field to store value which is come from previous page-->
<input type="hidden" name="keyword1" value="<?php echo $_POST['keyword'];?>"/>
<select name="sort" >
<option value="">Order By</option>
<option value="price_desc">Price descending</option>
<option value="price_asc">Price ascending</option>
<option value="date_asc">Most recent</option>
<input type="submit" name="sortingbtn" placeholder="Sort"/>
</select>
</form> // you didn't add form closing tag
现在,当您将submit
上方form
的{{1}}值传递给name=keyword1
时,可以在查询中使用它。