Reputation: 1945
I use the following query to show results from my search bar
$query =
"SELECT * FROM $usertable WHERE
($postcodelist LIKE '%$search%'
OR $city LIKE '%$search%')
AND $office <> ''
GROUP BY $office";
If I enter LS19 or Leeds, it shows me the leeds office's details as the postcode list i have is 4 digits max
However if I search LS19 6BR (my full postcode) it shows me nothing as this does not match the post code list at all.
I need to somehow search part of the user's input when then enter a postcode, but not when they enter a city for example.
Is this possible?
Thanks
Upvotes: 0
Views: 202
Reputation: 6202
Since you have 1 search term for 2 fields, this is tricky. I would consider splitting it into 2 search fields. However, barring that I would just go with:
$postcodesearch = substr($search,0,4);
$query =
"SELECT * FROM $usertable WHERE
($postcodelist LIKE '%$postcodesearch%'
OR $city LIKE '%$search%')
AND $office <> ''
GROUP BY $office";
Upvotes: 2