Show json from database

I’m working with a json structure that displays a quiz, but right now I don’t understand how to display it properly please help me, I want to read information from database and show in below json structure, i thank you

    "question_id" : 0,
    "question": "What is the original native name of Mount Rainier?",
    "answers": [
      {"id": 0, "text": "Tahoma"},
      {"id": 1, "text": "Shuksan"},
      {"id": 2, "text": "Stillaguamish"}

    "correct": 0
    "question_id" : 1,
        "question" : "Which image shows a close-up of the Nisqually Glacier?",
        "answers"  : [
            {"id"  : 0, "image" : "images/quizImages/glacier_01.jpg" },
            {"id"  : 1, "image" : "images/quizImages/glacier_02.jpg" },
            {"id"  : 2, "image" : "images/quizImages/glacier_03.jpg" },
            {"id"  : 3, "image" : "images/quizImages/glacier_04.jpg" }
        "correct"  : 3

Show json from database


Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

  1. Fetch your data from the database and make a multidimensional array using the data that is getting the database.
  2. Apply json_encode on final array

All methods was sourced from or, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Notify of

Inline Feedbacks
View all comments
Would love your thoughts, please comment.x