I am building a CRUD application using PHP and PDO.
I have a table with various foods and want to return results based on the first letter of user input. As in "return all foods starting with 'a'".
I have this query:
$sql = "SELECT *
FROM food
WHERE FoodName LIKE 'a%';
$userInput = $_POST['userInput'];
This obviously works and returns all food starting with an a.
But how can I query based on the user input, instead of writing the above for every alphabetical letter.
I cannot post the whole application, I have it on localhost, but I don't think this is necessary. What is the most efficient way to implement this? JS, PHP or a PDO command?