PHP从MySql以水平样式显示数据

I am trying to display all my site members info with avatar and some information in members page of my WordPress site.For this, I have written following code.It is displaying data with one single user in a row.What I am trying is to display multiple users like 4 to 5 members horizontally in a single row then start 2nd row similar like this https://stackoverflow.com/users Following is my code.how can achieve this

 <?php

    global $wpdb;
    $result = $wpdb->get_results( "SELECT id,display_name as pt,user_registered as re FROM wp_users  group by id"); /*mulitple row results can be pulled from the database with get_results function and outputs an object which is stored in $result */

    foreach($result as $row)
    {
     echo '<table><tr>';      
     echo '<td>'.get_avatar( $row->id,40 );
     echo '</td><td>'.$row->id."  ".$row->pt. "<br>" .$row->re. "</td></tr> 
    </table>";

    }

 ?> 

I prefer to solve the problem by using an count and define a fixed number of columns.

<?php

    global $wpdb;
    $result = $wpdb->get_results( "SELECT id,display_name as pt,user_registered as re FROM wp_users  group by id"); /*mulitple row results can be pulled from the database with get_results function and outputs an object which is stored in $result */

    $count = count($result);
    $columns = 5;

    echo '<table><tr>';

    foreach($result as $i => $row) {
        echo '<td>' . get_avatar( $row->id,40 ) . '</td>';
        echo '<td>' . $row->id . '  ' . $row->pt . '<br>' . $row->re . '</td>';

        $i++;
        if($i != $count && $i >= $columns && $i % $columns == 0)
            echo '</tr><tr>';
    }

    echo '</tr></table>';

?> 

Try with this,

<?php
global $wpdb;
$result = $wpdb->get_results( "SELECT id,display_name as pt,user_registered as re FROM wp_users  group by id");

?>

<div class="container">
<?php foreach($result as $row) { ?>
<div class="row">
  <div class="col-lg-3">
     <?php get_avatar( $row->id,40 ); ?><br>
     <?php echo $row->id." ".$row->pt;?><br>
     <?php echo $row->re;?>
  </div>
</div>
<?php } ?>
</div>