Skip to content
Advertisement

My sql query for item search is not working

Im building a restaurant website and i have to search for food items according to what the user inputs in the search bar. I have to sort the results by the most relevant one

UPDATED:

JavaScript

I have re formatted the latest sql statement and have executed the query but still it does not give me any desired output.. Now how shall i proceed?

Advertisement

Answer

First of all, don’t use variables in the string. You are using PDO, therefore, use prepared statements instead.

Also if I understood correctly you need the “LOWER” function for the string you are searching right? in that case, use PHP “strtolower” function once and give that variable to SQL statement

JavaScript

edited

if you want to loop over results replace

$results = $statement->fetchAll();

with:

JavaScript

If you Cannot or dont want to use prepared statemants then do so:

JavaScript
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement