Both search bring back the correct results, but when I tried combining the 2 queries, it ends up giving bad results.
$query3 = "SELECT *
FROM airport_countries, airports
WHERE airports.iso_country=airport_countries.code &&
airport_countries.name like '%$search%'
ORDER BY pageviews DESC";
$query2 = "SELECT *
FROM airports
WHERE name like '%$search%' or
municipality like '%$search%'
ORDER BY pageviews DESC";
VVVVVVVVV
SELECT *
FROM airport_countries, airports
WHERE airports.iso_country=airport_countries.code &&
airport_countries.name like '%$search%' or
airports.name like '%$search%' or
airports. municipality like '%$search%'
ORDER BY pageviews DESC
What am I doing wrong?
you problem aseems to be the operator precedence. to avoid that, just use braces:
i’d also recommend using
ANDinstead of&&(you’re writingorinstead of||– doesn’t look very consistent), but thats just my opinion for better readability and shouldn’t cause any difference.