How to replace USERNAME with NAME in "Who is Online"?

General questions relating to Joomla! 1.5 There are other boards for more specific help on Joomla! features and extensions.

Moderator: General Support Moderators

Forum rules
Forum Rules
Absolute Beginner's Guide to Joomla! <-- please read before posting.
Forum Post Assistant - If you are serious about wanting help, you should use this tool to help you post.
Locked
bmose14
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Jul 11, 2008 3:34 pm

How to replace USERNAME with NAME in "Who is Online"?

Post by bmose14 » Fri Jul 11, 2008 9:59 pm

Hi Guys,
I'm new to Joomla and no PHP master (yet) but I am trying to change the "Who's Online" module to display 'name' instead of username.

ex: Instead of: We have 1 member online * jsmith
ex: I want it to say: We have 1 member online * John Smith

I found this code in /modules/mod_whosonline/tmpl/default.php

Code: Select all

    if(($showmode > 0) && count($names)) : ?>
        <ul>
    <?php foreach($names as $name) : ?>
           <li><strong><?php echo $name->username; ?></strong></li> 
    <?php endforeach;  ?>
       </ul>
    <?php endif;


I think I need to modify:

Code: Select all

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


to something like

Code: Select all

      <?php echo $name->name; ?>  
but that doesn't seem to work.
I want it to look like it does in the login module where it says: "Hi, John Smith"
I think that code is in /modules/mod_login/tmpl/default.php

Code: Select all

    <div><?php echo JText::sprintf( 'HINAME', $user->get('name') ); ?></div>
Do I use a get('name')?

I'm sure it's something simple, but I don't have much experience with php.
Any suggestions? thanks!!
-Brian

Gergo Erdosi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4031
Joined: Sat Nov 11, 2006 9:34 pm
Location: Hungary

Re: How to replace USERNAME with NAME in "Who is Online"?

Post by Gergo Erdosi » Sun Jul 13, 2008 12:23 pm

It's not so easy as you think. :) Joomla! gets the usernames from the session table, and in that table there is only username and userid (and some others but those are not important for us now). That's why you can't get directly the names from the session table, you need to join the session table and the users table. For this open the /modules/mod_whosonline/helper.php file and change this code at the end of the file

Code: Select all

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

Code: Select all

		$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';
Then open the /modules/mod_whosonline/tmpl/default.php file and change

Code: Select all

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

Code: Select all

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

bmose14
Joomla! Apprentice
Joomla! Apprentice
Posts: 7
Joined: Fri Jul 11, 2008 3:34 pm

Re: How to replace USERNAME with NAME in "Who is Online"?

Post by bmose14 » Sun Jul 13, 2008 5:12 pm

It worked! Thanks so much Gergo, this is a great fix!
Now I'm going to try and use that info to figure out how to do the same with the users who are planning to attend events in EventList.

Thanks again!
-Brian :D

Gergo Erdosi
Joomla! Virtuoso
Joomla! Virtuoso
Posts: 4031
Joined: Sat Nov 11, 2006 9:34 pm
Location: Hungary

Re: How to replace USERNAME with NAME in "Who is Online"?

Post by Gergo Erdosi » Sun Jul 13, 2008 5:34 pm

You're welcome. :)

User avatar
wildomingues
Joomla! Apprentice
Joomla! Apprentice
Posts: 23
Joined: Thu Jul 17, 2008 5:22 pm
Location: brazil
Contact:

Re: How to replace USERNAME with NAME in "Who is Online"?

Post by wildomingues » Wed Sep 09, 2009 5:14 pm

It worked for me! Tks!!

jabbott777
Joomla! Intern
Joomla! Intern
Posts: 51
Joined: Tue Jan 26, 2010 10:37 pm

Re: How to replace USERNAME with NAME in "Who is Online"?

Post by jabbott777 » Thu Mar 24, 2011 4:37 am

I assumed that if I was to turn this into 1.6 language it would look like this:

Code: Select all

$query -> SELECT DISTINCT('u.name');
$query -> FROM('#__session AS a');
$query -> INNER JOIN ('#__users AS u ON u.id = a.userid');
$query -> WHERE ('a.client_id = 0');
$query -> AND ('a.guest = 0');
But, this kicks out a server error. Any idea how you would do this in Joomla 1.6?


Locked

Return to “General Questions/New to Joomla! 1.5”