In the table header, I use this to count the user's logins:
<?php
$db =& JFactory::getDBO();
$query="SELECT `created_by`, COUNT(`created_by`) AS logins
FROM `#__activities_activities`
WHERE `type` = 'com' AND `package` = 'users' AND `action` = 'login' AND `status` = 'logged in'
GROUP BY `created_by`";
$db->setQuery($query);
$login_count = $db->loadObjectList('created_by');
?>
In the detail of the table, I use this to display each user's login count:
<?php
foreach($form->data['VIPList'] as $detail):
?>
<?php
$logins = $login_count[$detail['acct_user_id']];
$logins = $logins->logins;
echo $logins;
?>
<?php
endforeach;
?>
This works perfectly in the CF form. I am trying to do the same thing, but within a CC connection. Each row in the connection contains the User ID. No matter HOW I try to adapt this code I cannot get it to work. I have tried this code (in a <td> on each row in the table body), but it does not display the login count:
<?php
$user="{USERS.id}";
$db =& JFactory::getDBO();
$query="SELECT COUNT(`created_by`) AS logins
FROM `#__activities_activities`
WHERE `type` = 'com' AND `package` = 'users' AND `action` = 'login' AND `status` = 'logged in' AND `created_by` = '$user'";
$db->setQuery($query);
$login_count = $db->loadResult('logins');
echo $login_count;
?>
It displays "0" for every row. When I display the query and run it in phpMyAdmin it returns the correct count for each user. Any idea why this will not work?