Skip to content
Advertisement

display multiple results from a sql query

so I am trying to display multiple results from a database when a query is searched, the query is passed from a search box on another page.

I have it displaying one result, but that is all it will display. I need it to display all the results that are relevant to the search query.

the php code is below

JavaScript

and the code for the search bar

JavaScript

Does anyone have any suggestions?

Thanks in advance;

Advertisement

Answer

You will need to place it in a while loop to show multiple results, the fetch function you’re using will only retrieve one row, if you place it in a loop you can keep fetching until there is nothing to fetch:

JavaScript

P.S. your code is vulnerable to SQL injection, you should read about prepared statements. More Info on that

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