X7 Chat Support Board
Welcome, Guest. Please login or register.
July 31, 2010, 07:48:42 PM

Login with username, password and session length
Search:     Advanced search
X7 Chat Version 3.0.0 Alpha 2 is now available (http://x7chat.com/support_forum/index.php?topic=3198.msg11497#new).
13036 Posts in 3760 Topics by 66536 Members
Latest Member: usheeenkogon
* Home Help Search Login Register
+  X7 Chat Support Board
|-+  X7 Chat Mods
| |-+  Mod Support
| | |-+  Who's Online = working but need help
« previous next »
Pages: [1] Reply Send this topic Print
Author Topic: Who's Online = working but need help  (Read 5042 times)
mac
Guest


Email
« on: September 17, 2006, 12:34:10 PM »
Reply with quote

Hi,
I've just started using this great chat program! I love it!

I'm using this script that I found on this site. I changed it a bit and I need some help with it. It's the 'who's online script' which I use on my index.php page which is seperate from X7Chat. It works great, but I would like to enhance it and I don't know much php, maybe somwonw here can help please!

Here's what I have:

<?
//connect to mysql
//change localhost, username and password to your mySQL username and password
mysql_connect("xxxx","xxxx","xxxx");
   
//select which database, change DBname
mysql_select_db("xxxxxx");

//select the table, should be right if you didn't change the prefix in the data base
$result = mysql_query("select * from x7chat2_online");


$expire_time = 240;
$exp_time = time()-$expire_time;
      $q = mysql_query("DELETE FROM x7chat2_online WHERE time<'$exp_time'");

//grab all the content


while($r=mysql_fetch_array($result))
{

   //modify these to match your mysql table columns that you want to display

   $usersonline=$r["name"];
   $room=$r["room"];


   //display the row
   echo "$usersonline";
}
?>

Currently, it shows who's online like this: 'user1user2user3'. How can I add a comma between the usernames so it's like this: 'user1, user2, user3' ?

Also, how can I get it to wrap around, maybe so it starts a new line after every five names or so, lile:

user1, user2, user3, user4, user5,
user6, user7

I suppose some kind of HTML table? Any suggestions greatly welcomed!
Report to moderator   Logged
E-Oreo
Administrator
Member
*****
Offline Offline

Posts: 3710


View Profile Email
« Reply #1 on: September 17, 2006, 01:56:06 PM »
Reply with quote

For the comma change
Code:

while($r=mysql_fetch_array($result))
{

   //modify these to match your mysql table columns that you want to display

   $usersonline=$r["name"];
   $room=$r["room"];


   //display the row
   echo "$usersonline";
}

to
Code:
$usersonline = '';
while($r=mysql_fetch_array($result))
{

   //modify these to match your mysql table columns that you want to display
   $room=$r["room"];

   $usersonline .= $r['name'] . ', ';
}

if($usersonline != '')
   echo substr($usersonline,0,strlen($usersonline)-3);
else
   echo 'No users online';

For the wrap just put the PHP code inside a <div> with the width that you want and let the browser wrap it.
Report to moderator   Logged
mac
Guest


Email
« Reply #2 on: September 17, 2006, 02:18:30 PM »
Reply with quote

Hmmm....thanks, that works but it intoduces one problem! My username is "Mike_M" and it displays "Mike_"

?!??!


Report to moderator   Logged
mac
Guest


Email
« Reply #3 on: September 17, 2006, 02:21:03 PM »
Reply with quote

Yep I see the problem is with all users: the last letter of their usernames are all missing!
Report to moderator   Logged
E-Oreo
Administrator
Member
*****
Offline Offline

Posts: 3710


View Profile Email
« Reply #4 on: September 17, 2006, 03:25:40 PM »
Reply with quote

Change the 3 to a 2 in
[CODE
substr($usersonline,0,strlen($usersonline)-3);
Code:
Report to moderator   Logged
madfiddler
Member
*
Offline Offline

Posts: 7


View Profile Email
« Reply #5 on: December 29, 2006, 08:43:53 PM »
Reply with quote

Using MKPortal, I couldn't get this to work as a PHP block as it displayed the members outside of the table, and therefore corrupted the look of the site.

This did work for me - it's just blank when there are no members online

Code:
<?
//select the table, should be right if you didn't change the prefix in the data base
$result = mysql_query("select * from x7chat2_online");


$expire_time = 10;
$exp_time = time()-$expire_time;
      $q = mysql_query("DELETE FROM x7chat2_online WHERE time<'$exp_time'");

//grab all the content

$usersonline = '';
while($r=mysql_fetch_array($result))

{

   //modify these to match your mysql table columns that you want to display
   $usersonline .= $r['name'] . ', ';

}

   //display the row
$content="members in chat $usersonline";

?>

However, the looks isn't quite how I want. Is there any way I can centre the text (it does it in the preview, but not the main site), and perhaps display the "members in chat" words in a different font?

Thanks,

m
« Last Edit: December 29, 2006, 08:47:19 PM by madfiddler » Report to moderator   Logged
Ardbeggordon
Member
*
Offline Offline

Posts: 19


View Profile
« Reply #6 on: June 29, 2008, 06:36:11 AM »
Reply with quote

I know this is a very old subject (sorry !) but has anyone managed to get this to work with phpbb3 ?
Or is there another way to get the who's online to show in phpbb3 ?
Thanks
Report to moderator   Logged
Peter Koster
Member
*
Offline Offline

Posts: 184


View Profile WWW
« Reply #7 on: June 29, 2008, 04:59:51 PM »
Reply with quote

Don't know about phpbb3 (haven't updated yet, since my phpbb2 has so many mods it's nearly 100 % spam free), but in version 2 you couldn't use 'foreign' php. There was a mod to make that possible, but I couldn't get it working.
Report to moderator   Logged

Peter
Squat toilets, travel guide about France
http://www.hurktoilet.nl/index-en.php
Ardbeggordon
Member
*
Offline Offline

Posts: 19


View Profile
« Reply #8 on: July 01, 2008, 01:02:16 PM »
Reply with quote

Thanks Peter , i spent a couple of hours trying various combinations of the php but couldn't get anything to appear !
Report to moderator   Logged
blablubbb
Member
*
Offline Offline

Posts: 8


View Profile
« Reply #9 on: April 10, 2009, 08:55:52 AM »
Reply with quote

You need to do the folowing:
1. Make a new php-file with the code of madfiddler above
2. Ad this to the beginning of this code (but after the opening tag of php (<?):
Code:
mysql_connect("localhost","username","password");
mysql_select_db("DBname");
While DBname, username and password need to be changed and maybe also localhost (in lots of cases it is just localhost)
3. Add this code at the end:
Code:
print "$content";
just after the definition of the $content variable and before the end-tag of the php (?>) in a new line.
4. Upload it somewhere at your server.
5.Add something like this into your forum-code (e.g.: in the overall-footer):
Code:
<iframe src="http://YOUR_FORUM.com/path_to_the_php-file/php-filename.php" name="whoisinchat" scrolling="auto" width="100%" height="300"></iframe>
You should modify the path to your php-file (and for a better loocking width and height and you could set scrolling to "no" and you can change the name and you can do some style-things at the css-file... but thats optional...according to your needs)
« Last Edit: April 10, 2009, 09:05:21 AM by blablubbb » Report to moderator   Logged
Pages: [1] Reply Send this topic Print 
« previous next »
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.9 | SMF © 2006-2009, Simple Machines LLC Valid XHTML 1.0! Valid CSS!
Page created in 0.112 seconds with 17 queries.