If you have your models setup correctly:
hasAndBelongsToMany if the user can be a part of many groups, or
User belongsTo Group | Group hasMany User if they only belong to one.
Then in the method your controller:
class GroupsController extends AppController
{
function index()
{
$this->Group->recursive = 2;
$this->set('groups', $this->Group->findAll()); // sets $groups
for
your view to access it hint: in your view, look at pr($groups); i'll
bet you find your users
}
}
in View:
<?php foreach ($groups as $group): ?>
<?php echo $group['Group']['name']; //or whatever field instead of
name ?>
<?php foreach ($group['User'] as $user): ?>
<?php echo $user['email']; //or whatever field instead of email ?
>
<?php endforeach; ?>
<?php endforeach; ?>
This isn't tested but it should give you a point in the right
direction
On Aug 14, 8:49 am, Wimg <[EMAIL PROTECTED]> wrote:
> The problem is like this, i have a database as below:
>
> user_id , group_id
>
> 1 1
> 2 1
> 3 2
> 4 2
>
> i wanna display users in the same group as a row in a table
>
> group1 group2
> 1 2
> 3 4
>
> i was thinking that I get group_id first, then use group_ id to get
> users belong to the same group_id. but i donot know how to do this in
> controller .
>
> any ideas ? thx in front
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Cake
PHP" 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
-~----------~----~----~----~------~----~------~--~---