Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6

Thread: Users Online

  1. #1
    New Coder
    Join Date
    Jul 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Users Online

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

    PHP Code:
    <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>

  • #2
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post
    You could check with an if statement if its the last entry, and then dont add the '-'

    one way to do that would be to get the number of records from mysql, using mysql_num_rows, and then use a variable that keeps track of where in the loop you are in.
    m6.net - windows webhosting
    my readlog - what I read

  • #3
    New Coder
    Join Date
    Jul 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I tried this and it still doesn't work!

    PHP Code:
    <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>
    Anyone think they could help me ?

  • #4
    Super Moderator JohnDubya's Avatar
    Join Date
    Nov 2006
    Location
    Missouri
    Posts
    634
    Thanks
    12
    Thanked 18 Times in 18 Posts
    Quote Originally Posted by birdbrain24 View Post
    PHP Code:
    <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>
    Well, you set $i to equal 0 before the while AND inside the while. So each time you're looping back through the while statement, it's setting $i to 0 again. Set $i to 0 outside only and let us know if that helps.

  • #5
    New Coder
    Join Date
    Jul 2007
    Posts
    32
    Thanks
    0
    Thanked 0 Times in 0 Posts
    i fixed what you said and it still shows the - after every username!

    Look at the code now:

    PHP Code:
    <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)){ 
         
        if(
    $count $i){ 
       
        echo(
    $users['username'].' - '); 
         
        
    $i++; 
         
        } 
         
        elseif(
    $count == $i){ 
       
        echo(
    $users['username']);   
           
        } 
       
      } 
    ?>  
    </body> 
    </html>

  • #6
    New to the CF scene
    Join Date
    Jan 2008
    Posts
    9
    Thanks
    0
    Thanked 1 Time in 1 Post
    to debug what is going on, you can echo $i . "<br>"; or something so you see what the $i value is in different iterations inside the while loop, that way it will be easy to fix for you. the variable is probably only 1 off for it to work, the approach is OK

    PHP Code:
    while($users mysql_fetch_array($users_query)){ 

         echo 
    $i "<br>";
        if(
    $count $i){ 
       
        echo(
    $users['username'].' - '); 
         
        
    $i++; 
         
        } 
         
        elseif(
    $count == $i){ 
       
        echo(
    $users['username']);   
           
        } 
       
      } 
    m6.net - windows webhosting
    my readlog - what I read


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •