Here i have one JSON response, in that response i am getting values like companyId,and divisionName etc..., now i want find companyId one means i want to find what is the company name, so written one function and also i got the company name, my problems is in this name i am not able to append same object
protected function getStates(){
// Cross validation if the request method is GET else it will return "Not Acceptable" status
if($this->get_request_method() != "GET"){
$response_array['status']='fail';
$response_array['message']='GET method only accept';
$response_array['data']='';
$this->response($this->json($response_array), 405);
}else{
$info_array = array(
"fields"=>"stateId,stateName,companyId",
"where"=>"stateStaus !='Inactive'"
);
$state_data = $this->GetRecords("state",$info_array);
if(count($state_data)>0) {
$companyId = $state_data['companyId'];
$check_info = array(
'fields'=>'companyName',
'where'=>'companyId = "'.$companyId.'" '
);
$companyName = $this->GetNameById('company',$check_info);
//$state_data['companyName'] = $companyName; //Company Name display
$response_array['status']='success';
$response_array['message']='Total '.count($state_data).' record(s) found.';
$response_array['total_record']= count($state_data);
$response_array['data']=$state_data;
$this->response($this->json($response_array), 200);
} else {
$response_array['status']='fail';
$response_array['message']='Record not found.';
$response_array['data']='';
$this->response($this->json($response_array), 506);
}
}
}
$this->response($this->json($response_array), 200); (i am getting response)
{
"status": "success",
"message": "Total 3 record(s) found.",
"total_record": 3,
"data": [
{
"stateId": "3",
"stateName": "Odisha",
"companyId": "1"
},
{
"stateId": "2",
"stateName": "Tamil Nadu",
"companyId": "1"
},
{
"stateId": "1",
"stateName": "Karnadaka",
"companyId": "1"
}
]
}
For finding companyName i wrote one function $companyName = $this->GetNameById('company',$check_info); here i am getting comapany name (Cibla).
My expected results
{
"status": "success",
"message": "Total 3 record(s) found.",
"total_record": 3,
"data": [
{
"stateId": "3",
"stateName": "Odisha",
"companyId": "1",
"companyName" : "Cibla"
},
{
"stateId": "2",
"stateName": "Tamil Nadu",
"companyId": "1",
"companyName" : "Cibla"
},
{
"stateId": "1",
"stateName": "Karnadaka",
"companyId": "1",
"companyName" : "Cibla"
}
]
}