Actions

Difference between revisions of "Display name instead of username in Who is online module"

From Joomla! Documentation

 
(3 intermediate revisions by 2 users not shown)
Line 1: Line 1:
 
If you want to display the name of the user instead of the username in the Who is online module, you need to do the following steps. The module gets the data from the session table, but that table doesn't contain the name of the user, only the username and the userid. That's why you need to join the session and the users table in the sql query. For this open the /modules/mod_whosonline/helper.php file and change
 
If you want to display the name of the user instead of the username in the Who is online module, you need to do the following steps. The module gets the data from the session table, but that table doesn't contain the name of the user, only the username and the userid. That's why you need to join the session and the users table in the sql query. For this open the /modules/mod_whosonline/helper.php file and change
  
  $query = 'SELECT DISTINCT a.username' .
+
<source lang="php">
    ' FROM #__session AS a' .
+
$query = 'SELECT DISTINCT a.username' .
    ' WHERE client_id = 0' .
+
  ' FROM #__session AS a' .
    ' AND a.guest = 0';
+
  ' WHERE client_id = 0' .
 +
  ' AND a.guest = 0';
 +
</source>
  
 
to
 
to
  
  $query = 'SELECT DISTINCT u.name' .
+
<source lang="php">
    ' FROM #__session AS a' .
+
$query = 'SELECT DISTINCT u.name' .
    ' INNER JOIN #__users AS u ON u.id = a.userid' .
+
  ' FROM #__session AS a' .
    ' WHERE a.client_id = 0' .
+
  ' INNER JOIN #__users AS u ON u.id = a.userid' .
    ' AND a.guest = 0';
+
  ' WHERE a.client_id = 0' .
 +
  ' AND a.guest = 0';
 +
</source>
  
 
There is only one step left, open the /modules/mod_whosonline/tmpl/default.php file and at the bottom change
 
There is only one step left, open the /modules/mod_whosonline/tmpl/default.php file and at the bottom change
  
  <?php echo $name->username; ?>
+
<source lang="php">
 +
<?php echo $name->username; ?>
 +
</source>
  
 
to
 
to
  
  <?php echo $name->name; ?>
+
<source lang="php">
 +
<?php echo $name->name; ?>
 +
</source>
  
 
This trick was written for Joomla! 1.5.
 
This trick was written for Joomla! 1.5.
  
 
[[Category:Tips and tricks]]
 
[[Category:Tips and tricks]]
 +
[[Category:Tips and tricks 1.5]][[Category:User Management]]

Latest revision as of 07:41, 19 September 2010

If you want to display the name of the user instead of the username in the Who is online module, you need to do the following steps. The module gets the data from the session table, but that table doesn't contain the name of the user, only the username and the userid. That's why you need to join the session and the users table in the sql query. For this open the /modules/mod_whosonline/helper.php file and change

$query = 'SELECT DISTINCT a.username' .
  ' FROM #__session AS a' .
  ' WHERE client_id = 0' .
  ' AND a.guest = 0';

to

$query = 'SELECT DISTINCT u.name' .
  ' FROM #__session AS a' .
  ' INNER JOIN #__users AS u ON u.id = a.userid' .
  ' WHERE a.client_id = 0' .
  ' AND a.guest = 0';

There is only one step left, open the /modules/mod_whosonline/tmpl/default.php file and at the bottom change

<?php echo $name->username; ?>

to

<?php echo $name->name; ?>

This trick was written for Joomla! 1.5.