0

i want to make system search for my site (ADS)

$sql->mysql_query(
"SELECT * FROM ads WHERE ads_catgs='".$gettagname."' 
AND ads_Marque LIKE '%$ads_Marque%' 
OR ads_Modèle LIKE '%$ads_Modèle%' 
OR ads_Type_de_carburant LIKE '%$ads_Type_de_carburant%' 
OR ads_Année_Modèle LIKE '%$ads_Année_Modèle%' 
OR ads_Kilométrage LIKE '%$ads_Kilométrage%' 
OR ads_city='".$getcity."' 
AND ads_title LIKE '%$getsearchfor%' 
ORDER BY ads_id DESC") or die($sql->mysql_error());

it's work but if I search for a ads title " Test " and ads_Marque "For_Test" .... it's select any ads title "test" and ads_Marque != "For_Test"

(I'm sorry for my bad english )

4
  • is ads_Marque supposed to be exactly =, if so why the like?
    – Drew
    Jul 22, 2015 at 5:37
  • because the input is a text Jul 22, 2015 at 5:40
  • course it is. But why add the extra risk if it = to begin with (like you did with = on $gettagname)
    – Drew
    Jul 22, 2015 at 5:44
  • this questions needs to be improved showing 1) the value of your variables, 2) a small dataset, 3) expected results, 4) any query changes with parenthesis. Only then can people authoritatively help you. Like can give unexpected results despite its simplicity, as can be seen here in what I wrote earlier today: (stackoverflow.com/a/31545517/1816093)
    – Drew
    Jul 22, 2015 at 6:07

1 Answer 1

0

Use trim to remove before and after spaces from keyword.

Try

$sql->mysql_query("SELECT * FROM ads WHERE ads_catgs='".$gettagname."' AND ads_Marque LIKE '%".trim($ads_Marque)."%' OR ads_Modèle LIKE '%".trim($ads_Modèle)."%' OR ads_Type_de_carburant LIKE '%".trim($ads_Type_de_carburant)."%' OR ads_Année_Modèle LIKE '%".trim($ads_Année_Modèle)."%' OR ads_Kilométrage LIKE '%".trim($ads_Kilométrage)."%' OR ads_city='".$getcity."' AND ads_title LIKE '%".trim($getsearchfor)."%' ORDER BY ads_id DESC") or die($sql->mysql_error());
0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.