I'm attempting to encode some values in JSON, so I can use them within other applications and also create a web API for them. to access them.
I have this SQL method to grab data from my database:
function getAllMessages() {
return getConnection()->query("SELECT * FROM allMessages ORDER BY programTimestamp DESC");
}
and I have this method to convert the data retrieved in JSON:
while( $row = getAllMessages()->fetch_assoc()) {
$json[] = $row;
}
echo json_encode( $json );
I've also tried this:
echo json_encode(getAllMessages()->fetch_assoc());
and I only get the first element/value returned from the SQL query.
echo $row[someColumn];do you get the expected results?