basically i have this..
[syntax=php]<?php
include '../core/connection_details.php';
mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_database");
$loggedin = mysql_query("SELECT `username`, `displayname`, `logged_in` FROM members WHERE logged_in='1'");
while($row = mysql_fetch_assoc($loggedin))
{
$user_in = $row['displayname'];
$user_name = $row['username'];
echo " <a href='".$user_name."'>".$user_in."</a> ";
}
?> [/syntax]
that works perfect how i want it.. the thing is.. as you can see when i echo out the user thats logged in i have put a space to seperate each logged in user but i dont want that i want a commer (,) after the username if there is another username after that one if you get me so say
ashwood
was online on his own.. no commer would show but if
ashwood & tim were logged in i want it to show as
ashwood, tim
if there was 3 people..
ashwood, tim, bob
if you get me? so only the commer if there is another username after that one.. like phpbb does if you go forum index then to the bottom of the page..
Thanks Ash
if..
Re: if..
yeah that works but i have 2 users logged in at the minute..
http://www.aatm-online.co.uk/index.php?
you can see it goes user1, user2, after user 2 i dont want a , if you get me..
http://www.aatm-online.co.uk/index.php?
you can see it goes user1, user2, after user 2 i dont want a , if you get me..
I would put a signature.. BUT, i don't have the time.
Re: if..
ashwood wrote:yeah that works but i have 2 users logged in at the minute..
http://www.aatm-online.co.uk/index.php?
you can see it goes user1, user2, after user 2 i dont want a , if you get me..
Yeah, I'll see what I can do.
Re: if..
Temor wrote:ashwood wrote:yeah that works but i have 2 users logged in at the minute..
http://www.aatm-online.co.uk/index.php?
you can see it goes user1, user2, after user 2 i dont want a , if you get me..
Yeah, I'll see what I can do.
okay cheers
I would put a signature.. BUT, i don't have the time.
Re: if..
If you put all of the users into an array, you can use impode() to put something between each element.
Re: if..
jacek wrote:If you put all of the users into an array, you can use impode() to put something between each element.
That's what I did.
[syntax=php]<?php
include '../core/connection_details.php';
mysql_connect("$db_host","$db_username","$db_password");
mysql_select_db("$db_database");
$username = array();
while($row = mysql_fetch_assoc($loggedin))
{
$user_in = $row['displayname'];
$user_name = $row['username'];
$username[] = '<a href="'. $user_name . '">' . $user_in . '</a>';
}
$username = implode(', ',$username);
echo $username;
?>[/syntax]
Took me a while because I got a strange error that somehow solved itself...
"Fatal error: [] operator not supported for strings"
Not sure what gave me that error, or why it suddenly disappeared
![Razz :P](./images/smilies/icon_razz.gif)
Re: if..
ashwood wrote:works a treat thanks a lot
p.s:
can you explain what implode() does please
http://php.net/manual/en/function.implode.php
Basically you implode an array with a character of choice and it returns a string with all the array elements, separated by the character you chose.
Re: if..
Temor wrote:ashwood wrote:works a treat thanks a lot
p.s:
can you explain what implode() does please
http://php.net/manual/en/function.implode.php
Basically you implode an array with a character of choice and it returns a string with all the array elements, separated by the character you chose.
ahhh
![Smile :)](./images/smilies/icon_e_smile.gif)
I would put a signature.. BUT, i don't have the time.