[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??
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