Retrieve result of a query in cakephp3

0

Hello everyone, as you will see, I have the following query in cakephp

$query = $this->PreguntasAlternativas->find();
    $query->select(['id_alternativa' => $query->func()->max('id_alternativa')
            ])->where(['id_pregunta' => $idquestion]);

this gives me an arrangement like that

query(array) 
   0(object)
      id_alternativa(null)

and what I want is to get the value that returns to me and then make a validation with it is because I do not know how to recover the value that the query returns to me to do something like that

if($query == null){
        $result = 1;
    }else{
        $result = $query->first()+1;
    }

that I was intendo but does not go through the help if please, thank you !!!!!

    
asked by Jonathan Cunza 13.08.2016 в 19:54
source

1 answer

0

My solution was to change the structure of my query

$query = $this->PreguntasAlternativas->find('all', ['conditions' => ['id_pregunta' => $idquestion]]);
    $result = $query->max('id_alternativa');
    if(!$result['id_alternativa']){
        $result['id_alternativa'] = 1;
    } else {
        $result['id_alternativa'] += 1;
    }

Graciasss

    
answered by 16.08.2016 / 17:41
source