$this->Post->find('first',array('conditions' =>
array('active'=>'1'),'order' => 'rand()'));
On 26 stu, 14:26, Giorgio <anothernetfel...@gmail.com> wrote:
> Ok, that's perfect.
>
> But now that i have an array with all posts that satisfy that condition,
> howto get a random one? Should i normally work with php here?
>
> In the Blog example (tutorial) we have 2 fields (time fields) that are
> automatically set by mysql. Is this a good practice? Why not set everything
> with php? In my case i have to add an added_date (that will be the date when
> the db row is created) and a posted_date (that will be set when the script
> will randomly hit that line, also changing from 1 to 0 the status value).
>
> Thanks
>
> 2010/11/26 Salines <nikola.parad...@gmail.com>
>
>
>
> > Why you complicated?
> > --------------------------
> > @giorgio,
>
> > for update /change status field in db table use
> > $this->Post->saveField('status','0');
> > or
> > $this->Post->saveField('status','1');
>
> > and select all active posts
> > $this->Post->find('All',array('conditions'=>array('status' => '1')));
>
> > On 26 stu, 13:40, Almudena Garcia <garcia.fra...@gmail.com> wrote:
> > > "SELECT * from table where status=1"
>
> > > This query will be something like:
>
> > > $options['fields'] = array(table.*);
> > > $options['conditions'] = array('table.status'=>1);
> > > $this->find('all',$options);
>
> > > Regards :)
>
> > > 2010/11/26 Giorgio <anothernetfel...@gmail.com>
>
> > > > Hi,
>
> > > > wow. I'm testing so much on CakePHP. I absolutely love MVC frameworks.
>
> > > > Today i've run into a new problem. I've created an application, but:
>
> > > > - Db fields are id, name, text, date, status. id and date are set by
> > mysql.
> > > > Name and text should be entered by the user. Status should be set to 0
> > for
> > > > every new entry. How can i do that? Of course, i can set a default
> > value in
> > > > mysql, but if i would set it from the application?
>
> > > > - Then, I need a page that if opened will output a random text (WHERE
> > > > status = 1). In a normal php script i'd use something like:
>
> > > > $query = "SELECT * from table where status=1";
>
> > > > $result = @mysql_query($query, db);
>
> > > > while ($row = @mysql_fetch_array($result))
>
> > > > $numbers[] = $row[id];
>
> > > > And then get a random element from the numbers array. How to translate
> > this
> > > > in cakephp?
>
> > > > Thanks
>
> > > > --
> > > > --
> > > > AnotherNetFellow
> > > > Email: anothernetfel...@gmail.com
>
> > > > Check out the new CakePHP Questions sitehttp://cakeqs.organdhelp
> > 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 cake-php@googlegroups.com
> > > > To unsubscribe from this group, send email to
> > > > cake-php+unsubscribe@googlegroups.com<cake-php%2Bunsubscribe@googlegroups.com>
> > <cake-php%2Bunsubscribe@googlegroups.com<cake-php%252Bunsubscribe@googlegroups.com>>For
> > more options, visit this group at
> > > >http://groups.google.com/group/cake-php?hl=en
>
> > Check out the new CakePHP Questions sitehttp://cakeqs.organd 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 cake-php@googlegroups.com
> > To unsubscribe from this group, send email to
> > cake-php+unsubscribe@googlegroups.com<cake-php%2Bunsubscribe@googlegroups.com>For more options, visit this group at
> >http://groups.google.com/group/cake-php?hl=en
>
> --
> --
> AnotherNetFellow
> Email: anothernetfel...@gmail.com
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 cake-php@googlegroups.com
To unsubscribe from this group, send email to
cake-php+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en
No comments:
Post a Comment