Yii2 Restful API : display the data from database into JSON format with specific condition SQL

I’m working on Yii2 restful API and want to display the data into JSON format. This is my structure database:

TABLE `volunteer`(
`volunteer_id` int(11) NOT NULL auto_increment,
`state_id` int(11) null
`nama` varchar(200) null

TABLE `state`(
`state_id` int(11) NOT NULL auto_increment,
`state` varchar(225) null

Basically, when I run at browser with specific ID = 1 (http://localhost/KDMA/web/index.php/volunteers/1) the data will display like this:

{
   "volunteer_id": "1",
   "state_id":"12",
   "nama": "Bentong",
}

that result is display the data from volunteer_id = 1. So, what I want to do right now is display the data from state_id, not volunteer_id. For example in SQL:

SELECT * FROM volunteer where state_id = 12;

What are the ways that can solve my problem?


Source: json

Leave a Reply