I am creating an Ajax autocomplete application and would like know if there is an SQL query I can use for this purpose – e.g if someone types “p” I would like to retrieve all words beginning with “p”, if they add “e” retrieve all words starting with “pe” – and continue like that.
Someone suggested the query below but I don’t think it’s what I’m looking for:
$query = "SELECT* FROM nametable WHERE names LIKE '$partialstring' ";
I’ve added % only on the right side since you would like to have only the words that are beginning with the input letters.
However, please don’t use this query until you’ve filtered it against SQL injections.