Taking the last position on the bench

Asked

Viewed 80 times

1

I need to get the last row of a column using Cakephp.

I’m trying like this:

$idAtual = $this->Albun->find('all', array('fields' => 'codigo'));

Only he’s returning all the lines. How to get only the last?

  • Try to give a order by desc id and return only one line with the limit. This is a possibility there are other.

2 answers

2


You have to add descending order and change the all for first

 $idAtual = $this->Albun->find('first', array('fields' => 'codigo', 'order' => array('codigo DESC')));

More hints:

Bookcakephp

0

could do something like this

case inserted at the time

echo $this->Albun->getInsertID();

Insert the code here by taking the last inserted in the base for the table

echo $this->Albun->getLastInsertID();

Browser other questions tagged

You are not signed in. Login or sign up in order to post.