Jump to content

User Online Seperate?


birdbrain24

Recommended Posts

How can i sperate the users in my code without there being a - left at the end ?

 

<html>
<head>
<title>RACE</title>
</head>
<body>
<?php
# Common functions!
session_start();
include('functions.php');
pageinfo('January 23 2008', 'January 23 2008');
connect();
sessioncheck();
lastaction();
$username=$_SESSION['username'];

$timenow = time();
$select = mysql_query("SELECT * FROM users WHERE lastaction > '$timenow' ORDER by username ASC");

  while($grab = mysql_fetch_array($select)){

    if($users['userlevel'] == 'Admin'){
      
    echo('<a href=\'profile.php?user='.$users['username'].'\'><b><font color=red>'.$users['username'].'</font></b></a> -"');
    
    }

elseif($users['userlevel'] == 'Head'){
  
echo('<a href=\'profile.php?user='.$users['username'].'\'><b><font color=orange>'.$users['username'].'</font></b></a> -"');

}

elseif($users['userlevel'] == 'Mod'){

    echo('<a href=\'profile.php?user='.$users['username'].'\'><b><font color=yellow>'.$users['username'].'</font></b></a> -"');
    
    }else{

    echo('<a href=\'profile.php?user='.$users['username'].'\'><b><font color=lightblue>'.$users['username'].'</font></b></a> -"');

    }

  }
?>
</body>
</html>

 

I would like to seperate the users with a -! Like it is here on the forums just using a -(dash) instide of using a ,(comma).

Link to comment
https://forums.phpfreaks.com/topic/87434-user-online-seperate/
Share on other sites

Do a count of the users returned.

Loop through the display

When the count = count

then use same line without the - on the end.

 

Also use double quotes in your html.

1) makes it easier to read.

2) less chance of forgetting to escape a single quote.

3) is the correct way to write code.

 

echo('<a href="profile.php?user='.$users['username'].'"><b><font color="orange">'.$users['username'].'</font></b></a> -');

 

 

Link to comment
https://forums.phpfreaks.com/topic/87434-user-online-seperate/#findComment-447201
Share on other sites

More:

 

<?php
$aCount = count($myArray);
$i = 0;
while($row = mysql_fetch_array($sql)){
     if($aCount == $i){
          echo rtrim($user, '-');
     }else{
          echo $user;
     }
     $i++;
}
?>

 

I can't seem to get this to work!

 

So i tried thid myself and i thought it would work but it doesn't

<html>
<head>
<title>RACE</title>
</head>
<body>
<?php
# Common functions!
session_start();
include('functions.php');
pageinfo('January 23 2008', 'January 23 2008');
connect();
sessioncheck();
lastaction();
$username=$_SESSION['username'];

$timenow = time();
$users_query = mysql_query("SELECT * FROM users WHERE lastaction > '$timenow' ORDER by username ASC");
$count = mysql_num_rows($users_query);
$i = 0;

  while($users = mysql_fetch_array($users_query)){
    $i = 0;
    if($count > $i){
  
    echo($users['username'].' - ');
    
$i++;
    
}

elseif($count == $i){
  
echo($users['username']);  
  
}
  
  }
?> 
</body>
</html>

Link to comment
https://forums.phpfreaks.com/topic/87434-user-online-seperate/#findComment-447315
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.