gpt4 book ai didi

PHP Reforce 搜索引擎

转载 作者:行者123 更新时间:2023-11-30 21:39:51 30 4
gpt4 key购买 nike

我有这个“搜索”选项,它在其中查找表格所请求变量的标题和类别。

//This could be Reference or Product Name
$name = mysqli_real_escape_string($con, sanitize($_GET['search']));

//this could be a specific category or Empty(used to reference number)
$category = mysqli_real_escape_string($con, sanitize($_GET['category']));
$x = 0;
$q = str_replace(array("\\",";"), "", $name); // remove ALL backslashes & remove ALL ";" -> for sql security: no (simple) injection of commands
$q = trim($q);
$search_exploded = explode(" ", $q);

foreach($search_exploded as $search_each ) {

$x++;

if($x == 1) {
$wherearr[]= "ads_title LIKE '%$search_each%' AND category_id = '$category' AND ads_active = 1 AND ads_end = 0";
} else {
$wherearr[]= "ads_title LIKE '%$search_each%' AND category_id = '$category' AND ads_active = 1 AND ads_end = 0";
}

}

//$wherearr[] is used to create a new variable $construct to insert to SQL like "Select * from Where $construct"

我希望人们也可以通过产品引用进行搜索。

目标是,当用户插入引用时,它会自动转到产品。

添加这个字段:

 $wherearr[]= "ads_reference LIKE '%$search_each%' AND ads_active = 1 AND ads_end = 0";

如何使用我之前创建的表单来完成?

最佳答案

不确定我是否完全理解你的问题,但我会尝试。

首先尝试从 GET 请求中提取所有你想要的数据。

一些假设:

  1. 您使用了 AND category_id = '$category' 所以我假设 $_GET['category'] 检索 category_id。
  2. 在提取 $_GET['search'] 时,您会得到由空格分隔的名称列表。因此,如果您有 foobar 这样的名称,则 $_GET['search'] 将是“foo bar”
  3. 如果 category_id 为空,我假设 $name 包含 Reference

现在试试这段代码:

$name = mysqli_real_escape_string($con, sanitize($_GET['search']));
$category_id = mysqli_real_escape_string($con, sanitize($_GET['category']));
$q = str_replace(array("\\",";"), "", $name);

$search_exploded = explode(" ", trim($q));
$wherearr = array();
$querySufix = " AND ads_active = 1 AND ads_end = 0";

foreach($search_exploded as $search_each) {
if ($category_id)
$wherearr[]= "ads_title LIKE '%$search_each%' AND category_id = '$category_id '" . $querySufix;
else
$wherearr[]= "ads_reference LIKE '%$search_each%'". $querySufix;
}

关于PHP Reforce 搜索引擎,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52136702/

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