Wednesday, November 23, 2011

Re: How to get information in a mysql table from a different controller.

Does your posts table have a field called period or is it period_id? If it's period, that's bad database design. You should change it to period_id so that it relates to the id column in the periods table. Then your problem is an easy one to overcome using table associations.

Jeremy Burns
Class Outfit

http://www.classoutfit.com

On 22 Nov 2011, at 18:08, GG wrote:

I have two tables, a posts table, and a periods table.

The posts table has a user_id, title, body, period.

The periods table has a user_id, title, period.

I can easily get the information from the posts table in my
PostsController.php:

$this->set('period1', $this->Post->find('all', array(
  'conditions'=>array('user_id'=>$this->Session-
read('Auth.User.id'), 'class_period'=>1)
  )));

But I cannot get the information from the periods table. I think this
would be the equivalent of a Left Join?

I would like to echo all periods with a user_id that matches the
(Auth.User.id).

Thanks!

--
Our newest site for the community: CakePHP Video Tutorials http://tv.cakephp.org
Check out the new CakePHP Questions site http://ask.cakephp.org and help others with their CakePHP related questions.


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

No comments: