0

[ASK] I have 2 table in MySql database

|Questions|
------------------------------
questionID|question|answer


|Options|
------------------------------
Id|questionID|option|result

i want to display the table like this on angularjs

questionID -> question -> - Option1
                          - Option2 (Answer)
                          - Option3
                          - Option4

I know the query of that.. but the problem is when i load to angular cannot load properly so i just want to know that how to load to angular using php??

1 Answer 1

1

We can do two different way one write Web service using Restful or SOAP and other method using PHP, pull the data from table and frame JSON object to consume from AngularJS. In AngularJS write HTTP request in service layer like below.

getQuestions: function(){
    $http.get("http://example.com/questions.php")
    .then(function(response) {
        return response.data;
    });  
}

questions.php JSON output

[
   {
      "questionId":"123",
      "question":"Your question",
      "options":[
         {
            "option":'Option1',
            "correct":false
         },
         {
            "option":'Option2',
            "correct":false
         },
         {
            "option":'Option3',
            "correct":true
         },
         {
            "option":'Option4',
            "correct":false
         }
      ]
   },
   {
      "questionId":133,
      "question":"Your question1",
      "options":[
         {
            "option":'Option1',
            "correct":false
         },
         {
            "option":'Option2',
            "correct":true
         },
         {
            option:'Option3',
            "correct":false
         },
         {
            "option":'Option4',
            "correct":false
         }
      ]
   }
]

https://github.com/kalaikt/pooling/blob/master/webservice/libs/pooling.php https://github.com/kalaikt/pooling/blob/master/app/services/customersService.js

Sign up to request clarification or add additional context in comments.

2 Comments

i still confused in query in questions.php, when i encode like "echo json_encode($data);" then display just question and questionID but not the option and answe
Updated my answer and also refer my Github you will get idea.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.