I'm making an OpenSearch plugin for my site and would like to return specific keywords matching a user's input, in the same sort of way as Google Suggest works.
For example, if a user enters "PL" and then pauses, I want my search script to search a number of fields in my MySQL database and return any word present in the data starting with PL, ie plastic, plasticity, plasma etc.
I can obviously search for the presence of the keyword by doing a simple search like this:
SELECT * FROM cms WHERE published = 'Yes' AND (title LIKE '%$query' OR text LIKE '%query') ORDER BY id DESC
However, what I'm not sure about is how to get the PHP to return only the specific keyword from this data. I'd like to get the code to return a list of all of the distinct words starting with PL from across the database, so I can display the most common ones to the user in the search suggestions dropdown on the OpenSearch box.
Does anyone have any idea how I might do this, please? I am a bit baffled as the correct manner in which to code this.
Many thanks for reading.