I have a function in my Model which is passed a single value and in which I have a query which is giving me two results.
public static function updImgtbl($id)
{
$total_images = 0;
$images_uploaded = 0;
$sqlquery = "SELECT SUM(CASE WHEN ims.`installation_id` = $id THEN 1 ELSE 0 END) AS total_images,
SUM(CASE WHEN ims.`image_upload_flag` = 1 AND ims.`installation_id` = $id THEN 1 ELSE 0 END) AS images_uploaded
FROM `installation_images_site` ims
INNER JOIN `installations` ins ON ins.`id` = ims.`installation_id`
WHERE (ims.`image_upload_flag` = 1 AND ims.`installation_id` = $id)
OR (ims.`installation_id` = $id)
GROUP BY ims.`installation_id`";
$pt = Yii::$app->db->createCommand($sqlquery)->queryAll();
foreach ($pt as $val)
{
$total_images= $val['total_images'];
$images_uploaded = $val['images_uploaded'];
}
return ["total_images" => $total_images, "images_uploaded"=>$images_uploaded];
}
This function is called from an API
$response = Installations::updImgtbl($install_id);
print_r($response);
exit();
The response is below
Array
(
[total_images] => 4
[images_uploaded] => 1
)
But I want to get these values in a variable in my API. How can I achieve it?