gpt4 book ai didi

php - 如何使用 PHP 创建搜索按钮

转载 作者:行者123 更新时间:2023-11-29 06:38:09 25 4
gpt4 key购买 nike

我想创建搜索按钮来查看数据库中的项目。

<form  method="post" name="searchdeals">
<h5 class="display-5 text-left py-3">Find a favourite vehicle </h5>
<div class="form-group select">
<select name="manufacturer_code" id="manufacturer_code" class="form-control" onchange="getState(this.value);">
<option selected>Select Brand</option>
<?php $ret="SELECT * FROM tbl_manufacturer";
$query= $dbh -> prepare($ret);
$query-> execute();
$results = $query -> fetchAll(PDO::FETCH_OBJ);
if($query -> rowCount() > 0)
{
foreach($results as $result)
{
?>
<option value="<?php echo htmlentities($result->manufacturer_code);?>"><?php echo htmlentities($result->manufacturer_name);?></option>
<?php }} ?>
</select>
</div>
<div class="form-group select">
<select name="model_code" id="model_code" class="form-control">
<option selected>Select Model</option>
</select>
</div>
<div class="form-group">
<button type="submit" name="searchdeals" value="Filter" class="btn btn-block btn-warning"><i class="fa fa-search" aria-hidden="true"></i> Search Vehicle</button>
</div>
</form>

这是我搜索项目的表单。因此可以向我建议如何创建查询和代码来创建搜索按钮。

我知道在查询中使用 LIKE OPERATOR,但我不知道如何编写代码

操作页面

if(isset($_POST['searchdeals'])){

$valueToSearch = $_POST['model_code'];

$sql = "SELECT tbl_manufacturer.manufacturer_name, tbl_model.model_name, tbl_model.model_type, tbl_vehicle.*, tbl_company.comp_name
FROM tbl_vehicle
INNER JOIN tbl_company ON tbl_vehicle.comp_id = tbl_company.comp_id
INNER JOIN tbl_model ON tbl_vehicle.model_code = tbl_model.model_code
INNER JOIN tbl_manufacturer ON tbl_model.manufacturer_code = tbl_manufacturer.manufacturer_code";
$query = $dbh -> prepare($sql);
$query->execute();
$results=$query->fetchAll(PDO::FETCH_OBJ);

最佳答案

首先,您需要对表单执行如下操作:

<form  method="post" name="searchdeals" action="/action_page.php">

action_page.php 应包含使用表单中的 $_POST 变量来构建 SELECT 语句的代码。

关于php - 如何使用 PHP 创建搜索按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52863116/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com