I have a VIEW with 4 columns that I’m basically using as a Full-Text search. The user enters a string into a textbox and it queries the VIEW like so:
SELECT * FROM vw_clients WHERE
col1 = "'%".$userInput."%'"
OR col2 = "'%".$userInput."%'"
OR col3 = "'%".$userInput."%'"
OR col4 = "'%".$userInput."%'"
My results are returned correctly, but is there a way to determine which columns contained the search term? Either via MySQL or PHP?
Not directly in MySQL, but there are hideously ugly hacks:
in php, it’d be a matter of looping over the fields in the result set and doing a
strpos()check. Either way… ugly.