The first param for find() should be one of 'first', 'all', 'list', etc.

But, if all you want is a single value, use field():

function newpil() {
        $pilid = $this->Pil->field(
                'pilid',
                array(
                        'Pil.user_id' => $this->Session->read('User.id')
                )
        ) + 1;
        
        ...
}


That being said, I wonder if you're heading into other problems here.
Do you know that your table will have duplicates for pilid? Because
they will only ever be unique for a particular user_id.

In fact, I don't know why you're not just using the primary key for
this. It's an auto_increment field and is designed for just this
purpose--increment the value for new records while also ensuring that
it's unique across all records.

On Tue, Sep 22, 2009 at 5:50 PM, Steppio <stepisgr...@hotmail.com> wrote:
>
> Hi everybody, this ones been doing my head in for some time now, hope
> you can help me out, im sure its very simple but i just cant get it
> working. Firstly the table structure is like this:
>
> CREATE TABLE pil (
>        id int(11) unsigned NOT NULL auto_increment primary key,
>        user_id int(11) unsigned not null,
>        pilid int(11) unsigned NOT NULL,
>        pcode varchar(255),
>        quantity text not null,
>        created DATETIME,
>        modified DATETIME
> )ENGINE=InnoDB DEFAULT CHARSET=latin1;
>
> And this is inside my pils_controller.php:
>
> function newpil() {
>                $user_id = $this->Session->read('User.id');
>                $pilid = $this->Pil->find(
>                array(
>                'conditions' => array('Pil.user_id' => $user_id),
>                'fields' => array('Pil.pilid'),
>                'order' => array('Pil.pilid DESC'),
>                ));
>
>                $pilid2 = ($pilid['Pil']['pilid'] + 1);
>
> ...
> }
>
> What i want is for the above function to pick out the last pil
> (product inquiry list) that the user set-up and to add a 1 to that.
>
> Any ideas where im going wrong? Any help will be greatly appreciated.
>
> Thank you
> Ste
> >
>

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to cake-php@googlegroups.com
To unsubscribe from this group, send email to 
cake-php+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to