Re: foreach data displaying in all instances instead of only related id

2009-05-22 Thread Teh Treag

programguru,

Filtering of data should not be done in your view.
It doesn't sound like your associations are correct.  Or possibly you
are retrieving your data incorrectly?  Can you post your models, and
your tasks controller?

On Associations -
You may find this image informative -
http://learn.kohanaphp.com/wp-content/uploads/2008/04/ruby-on-rails-data-relationships.png
Your relationship between Tasks and Comments should be similar to,
Dorms and Students.  You can check your database tables and
review your model associations.


On how you get your data -
In your tasks_controller.php, view action, you should have something
like,

public function view($id=null){
  if(!empty($id)){
$this->Task->recursive=1; //  $this->Task->recursive > -1;
$conditions=array('Task.id'=>$id);
$task=$this->Task->find("first",compact('conditions));
$this->set(compact('task'));
  }
}

I hope this helps.

-teh

On May 22, 12:52 am, programguru  wrote:
> i would just like my comments to display only to the task id they are
> associated with, but for some reason all comments are printing in all tasks.
>
> my relations are all setup perfect and tested with debug etc. but i just
> need to be able to filter the comments so they only display to the tasks
> they are associated with.
>
> I assume an id will be required in the foreach  () but I tried many
> variations with only errors or no output.
>
> here is my code:
>
> 
> foreach ($task['Comment'] as $Comment => $comment ):
>
> echo $comment['comment'];
>
> endforeach;
>
> ?>
> --
> View this message in 
> context:http://www.nabble.com/foreach-data-displaying-in-all-instances-instea...
> Sent from the CakePHP mailing list archive at Nabble.com.
--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---



foreach data displaying in all instances instead of only related id

2009-05-21 Thread programguru


i would just like my comments to display only to the task id they are
associated with, but for some reason all comments are printing in all tasks.

my relations are all setup perfect and tested with debug etc. but i just
need to be able to filter the comments so they only display to the tasks
they are associated with.

I assume an id will be required in the foreach  () but I tried many
variations with only errors or no output. 

here is my code:

 $comment ):

echo $comment['comment']; 

endforeach; 

?>
-- 
View this message in context: 
http://www.nabble.com/foreach-data-displaying-in-all-instances-instead-of-only-related-id-tp23664815p23664815.html
Sent from the CakePHP mailing list archive at Nabble.com.


--~--~-~--~~~---~--~~
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
-~--~~~~--~~--~--~---