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
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
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
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.