Skip to content
Advertisement

How to create an array from a MySQL query?

I have a HTML search form made with PHP that connects to a MySQL database, finds a table with columns and rows and then displays this data with an echo under the table.

JavaScript

The columns are id, name, short, short_withtag and url. The problem is, if I enter a keyword like pie (such a term existing in all of the rows) it will display only one search result. How do I make it display more than one?

Here is the query I use:

JavaScript

Advertisement

Answer

Just get all rows into an array and then output them with a foreach loop.

You can do that like this:

JavaScript

Note that this is a quite obsolete and not very secure or maintainable way of doing things.

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