Ciao a tutti,
ho creato questo script per visualizzare le informazioni di utenti online entro un determinato lasso di tempo.

Codice PHP:
    //IMPOSTO IL NUMERO DI UTENTI DA CERCARE PER PAGINA
    
$primo=0;
    
$per_page25;

    
// IMPOSTO IL DELAY
    
$delay3000;
    
$sess_online=0;


    
// FACCIO UNA SELEZIONE UNIVOCA DI TUTTI GLI ID PRESENTI NELLA TABELLA SESSIONI
    
$query_online=mysql_query("SELECT DISTINCT creation_date, user_id FROM sessioni GROUP BY user_id ORDER BY creation_date DESC LIMIT $primo$per_page");
    while (
$cerca=mysql_fetch_array($query_online)){

        
//SELEZIONO LE INFORMAZIONI CHE MI INTERESSANO DI OGNI UTENTE CHE MI VIENE RESTITUITO DALLA QUERY PRECEDENTE
        
$queryb=mysql_query("SELECT timestamp, username, avatar, sesso FROM utenti WHERE id=$cerca[user_id] ORDER BY timestamp DESC");
            while (
$cercab=mysql_fetch_array($queryb)){

            
// OTTENGO L'ULTIMO TIMESTAMP DELL'UTENTE
                
$check_sess$timestamp $cercab["timestamp"];

            
// SE L'UTENTE E' ONLINE INCREMENTA IL NUMERO
                    
if ($check_sess <= $delay){
                    
$sess_online++;

//PER OGNI UTENTE ONLINE CREO UN DIV CON LE SUE INFO
echo"<div class='div_avatar2' align='left'>
    <a href='messaggi.php?id=
$cerca[user_id]'>
    [img]utenti/
$cerca[user_id]/mini/$cercab[avatar][/img]
    [b]<u>
$cercab[username]</u>[/b] </a>

    [url='messaggi.php?id=
$cerca[user_id]'][img]img/mail.png[/img][/url]
    [url='profilo.php?id=
$cerca[user_id]'][img]img/foto.png[/img][/url]

    </div>"
;


                    }
                }
            } 
Il campo creation_date viene aggiornato ad ogni azione dell'utente sul sito con l'ultimo timestamp.

Il problema è che ho diversi errori, da un numero errato di utenti, a utenti ripetuti due volte, e addirittura non ordinati per creation_date desc, ma alla rinfusa...

avete idee?

Grazie