On 7 Aug 2010, at 01:35, Dave Maharaj wrote:
> I am trying to add the viewed by 1 for each view but it will not save.
>
> I have:
>
> $viewed = $mail['Sendout']['viewed'];
>
> $total = $viewed + "1";
> // tried $total = $viewed ++;
> // $total = $viewed + ‘1’;
> // $total = $viewed + 1;
>
>
>
> debug($total); //shows db count plus 1
>
> $this->Sendout->id = $mail['Sendout']['id'];
>
> $this->data['Sendout']['lastview'] = date('Y-m-d H:i:s');// this field saves
> the last view timestamp
> $this->data['Sendout']['viewed'] = $total; // this never saves db is int(11)
>
> $this->set('sendout', $mail);
>
> $this->Sendout->save( $this->data, true );
>
> Any ideas where I am going wrong?
yeah. you've got things a little skewed.
try
$total = $viewed +1; // its an integer so you shouldnt quote it
$this->data['Sendout']['id'] = $mail['Sendout']['id'];
$this->data['Sendout']['viewed'] = $total;
$this->data['Sendout']['lastview'] = date('Y-m-d H:i:s'); // actually you could
just use the modified field for this (if you've got one in your table) as that
gets updated automatically.
$this->Sendout->save($this->data);
alternatively
$this->Sendout->id = $mail['Sendout']['id'];
$this->Sendout->saveField('viewed',$viewed);
will just save the field with the updated value
HTH
--
Mike Karthäuser
Managing Director - Brightstorm Ltd
Email: [email protected]
Web: http://www.brightstorm.co.uk
Tel: 07939 252144
Address: 1 Brewery Court, North Street, Bristol, BS3 1JS
Check out the new CakePHP Questions site http://cakeqs.org and help others with
their CakePHP related questions.
You received this message because you are subscribed to the Google Groups
"CakePHP" 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