By benjamin beaugh on Friday, 12 June 2015
Posted in General Issues
Replies 8
Likes 0
Views 480
Votes 0
Hi! Id like to make a custom module or just know how to properly query and display this from the database...

id like to display all the group names from a specific category with a number showing the total amount of groups like below:

There are 3 groups in this category
Group 1
Group 2
Group 3

Thank you for any help you can provide!
Bizzo
Hello B,

I can't access your backend. By the way, did you echo the results? You might want to use var_dump instead:


// Get total number of groups
$groupsModel = FD::model( 'Groups' );
$options = array();
$options['category'] = 123 // your category ID
$groups = $groupsModel->getGroups($options);

var_dump($groups); // to see the results

foreach ($groups as $group) {
echo $group->getName();
}
·
Friday, 12 June 2015 11:32
·
0 Likes
·
0 Votes
·
0 Comments
·
Hi Bizzo,

If you look the model for groups at administrator/com_easysocial/models/groups.php there is a method getTotalGroups() maybe you can modify from it or I guess you can use the method getGroups() and supply it with the category id like array( 'category' => yourcategoryid)

Thanks,

jackson
·
Friday, 12 June 2015 07:07
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello Bizzo,

Yes, you can use getTotalGroups() function in model groups to get the total and and also getGroups() to get the groups filtered by category. Here is how you use it:

Get Total Group in specific category.

// Get total number of groups
$groupsModel = FD::model( 'Groups' );
$options = array();
$options['category_id'] = 123 // your category ID
$totalGroups = $groupsModel->getTotalGroups($options);



Get Group in specific category.

// Get total number of groups
$groupsModel = FD::model( 'Groups' );
$options = array();
$options['category'] = 123 // your category ID
$totalGroups = $groupsModel->getGroups($options);


Hope this helps.
·
Friday, 12 June 2015 10:37
·
0 Likes
·
0 Votes
·
0 Comments
·
Awesome! thanks Nick!

I got the first one to work, shows the total number of groups..

the second one only outputs the word "array"

Maybe im doing something wrong?

B
·
Friday, 12 June 2015 10:45
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello B,

Can you provide me the access to your FTP and which file you are referring to so I can fix the code for you.
·
Friday, 12 June 2015 11:06
·
0 Likes
·
0 Votes
·
0 Comments
·
here ya go..

you can view the module on the front page
·
Friday, 12 June 2015 11:12
·
0 Likes
·
0 Votes
·
0 Comments
·
thank you! this did the trick!
and thanks Jackson for getting me on the right track!

cheers
Bizzo
·
Friday, 12 June 2015 11:42
·
0 Likes
·
0 Votes
·
0 Comments
·
Hello B,

You're welcome.
·
Friday, 12 June 2015 12:36
·
0 Likes
·
0 Votes
·
0 Comments
·
View Full Post