Filter Data from a PHP database list from an Input

Asked

Viewed 119 times

0

I have an input text with the event onkeyup in which I type a word and it is comparing to a database list and returning a button with the same case..

I want that in the course that I type go appearing the options, example:

I have a list of the words test, tornado, storm, storm and when you already type the t comes up the three options and as you type you will delete some.

Remarks :

I’m using ajax to generate the buttons dynamically, but I look for a solution within php for the problem

For now it’s only comparing if the word is exactly the same as the one I typed in the input to print the button, I want it to print the buttons in the course I type.

It has to be with button, can not select nor options like datalist of Html5.

  • Can you show how buttons are being generated dynamically? I am producing a script with no database.

1 answer

1


The only way to do this without updating the page is with Ajax.

To do this you have to use the sql LIKE operator along with the %:

"SELECT coluna FROM tabela WHERE coluna LIKE '$variavel%' " 

Where '$variable' is the return of your input and '%' says it has more characters later.

There’s more to this link https://www.w3schools.com/sql/sql_like.asp

  • Thanks, had forgotten the like, perfectly solved what I was looking for, just to complement for those who need, the syntax would be WHERE name LIKE '%$Aquiseriaovalor%' "; the value between % %, Hug !

  • If it is not really necessary it is best to leave '%' only at the end to save database processing.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.