I have this Search option, where it looks for the Title and the Category Referent to the variable requested by the FORM.
//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"
I want to able people to search also by product reference.
The goal is, when the person inserts the reference, it will automatically go to the product.
Add this field:
$wherearr[]= "ads_reference LIKE '%$search_each%' AND ads_active = 1 AND ads_end = 0";
How can I do it using the form that I created before?
Aucun commentaire:
Enregistrer un commentaire