Ho questa funzione in php

Codice PHP:
function contatti($username)
{    
$query sprintf("SELECT jid,nick FROM jiveRoster WHERE username ='%s'",
   
mysql_real_escape_string($username));

$result mysql_query($queryconnectdb());

// Check result
// This shows the actual query sent to MySQL, and the error. Useful for debugging.

    
if (!$result) {
       
$message  'Invalid query: ' mysql_error() . "\n";
       
$message .= 'Whole query: ' $query;
       die(
$message);
       }

// Use result
// Attempting to print $result won't allow access to information in the resource
// One of the mysql result functions must be used
// See also mysql_result(), mysql_fetch_array(), mysql_fetch_row(), etc.
    
while ($row mysql_fetch_assoc($result)) {
       
$jid_contact=$row['jid'];
       list(
$contact_username$contact_domain) = split("@"$jid_contact); 
           if (
$contact_domain == 'jabberout.com'){
               echo 
"[*]<a href=/portal/?user=".$contact_username." title='".$contact_username."' />";
               
$reader=vcard($contact_username);
               
//var_dump($reader);
    
if (($reader->PHOTO->TYPE)){
    echo 
"[img]data:".($reader->PHOTO->TYPE).";base64,".($reader->PHOTO->BINVAL)."[/img]";
    }
    else {
    echo 
"[img]img/avatar_default.png[/img]";
    }
    echo 
"</a><a href=/portal/?user=".$contact_username." title='".$contact_username."' />";
    if ((
$reader->NICKNAME)){
    echo (
$reader->NICKNAME);
    }
    else {
    echo 
$contact_username;
    }
        echo 
"</a>";
           }
    }
mysql_free_result($result);

che mi produce una lista in verticale, ora vorrei
impostare con i css questa lista come il box in questa immagine

Ossia lista orizzontale a tre a tre !!!

Ho cercato di clonare il codice, ma è troppo complicato e anche i tutorial purtroppo non mi hanno aiutato

forse qui riesco a trovare una soluzione