If you just added the record then

$this->Model->getLastInserID(); //will give you the id you're looking
for

Now, suppose you added the record a while ago, and you just want to
find the highest ID, then you can add the following to your app_model:

 function getHighestID()
 {
  $res = $this->query("Select `{$this->name}.id` from `{$this->name}`
ORDER BY `{$this->name}.id` DESC LIMIT 1";
  return $res[$this->name]['id'];
 }


Then from any controller you can do:

 $this->Model->getHighestID();

On Feb 9, 3:00 pm, Salam Fall <[EMAIL PROTECTED]> wrote:
> Just solved the problem
> Here is how I have done it
>                          $ret = $this->Client->query("Select id from clients 
> order by id
> DESC LIMIT 1");
>                          $newid=$ret[0]['clients']['id'] + 1;
>                          $yr=date("y");
>                          $account="$branch-$yr-00$newid";
>                         $this->data['Client']['acct_numb'] = $account;
>                         $this->Client->create();
>                         if ($this->Client->save($this->data)) etc....
>
> Now my other question is how do i create my own classes and make them
> available in the controller and the view??
>
> On Feb 9, 5:34 pm, Salam Fall <[EMAIL PROTECTED]> wrote:
>
>
>
> > Here is what i have done so far but it's not working
> >                           $branch="SEN";
>
> >                         $ret = $this->Client->findBySQL("Select id from 
> > clients order by id
> > DESC LIMIT 1");
> >                         $lastId=$ret[0]['id'];
> >                          $act=$lastId + 1;
> >                         $yr=date("y");
> >                          $account="$branch-$yr-00$act";
> >                           $this->data['Client']['acct_numb'] =
> > $account;
> >                         $this->Client->create();
> >                         if ($this->Client->save($this->data) etc....
>
> > On Feb 9, 5:31 pm, Salam Fall <[EMAIL PROTECTED]> wrote:
>
> > > Nubee here
>
> > > How do I find the last record in the database and have it's ID value
> > > in the controller and be able to manipulate it mathematically.
>
> > > Because all i want to do is put the ID of the last record of the
> > > Clients table add 1 to it and append the result to a string that will
> > > be used to create the Client account number.
>
> > > Also if I want to create my own custom functions or classes to add to
> > > my cake APP how do I do that.
>
> > > Thanks for your help.- Hide quoted text -
>
> - Show quoted text -
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake 
PHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to