我有这个搜索选项,它在其中查找表单请求的变量的标题和类别引用。
//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";
如何使用我以前创建的窗体来完成它?
1条答案
按热度按时间rnmwe5a21#
我不确定我是否完全理解你的问题,但我会尽力的。
首先尝试从
GET
请求。一些假设:
你曾经
AND category_id = '$category'
所以我想$_GET['category']
检索类别id。提取时
$_GET['search']
你得到的名字列表用空格隔开。如果你有这样的名字foo
以及bar
这个$_GET['search']
将是“foo bar”如果
category_id
是空的我想$name
包含引用现在尝试以下代码: