Skip to content
Advertisement

PHP & MYSQL: Convert rows and columns to json objects

I’m trying to get all of the rows and columns of a MYSQL table to be objects in an array so I can retrieve them via javascript.

Here’s what I’ve got so far:

JavaScript

The object at the end should look something like this:

JavaScript

Advertisement

Answer

What about doing it in two (I mean three!) lines?

JavaScript

PS. Using SELECT * is considered bad practice.

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