1

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>";

    }

 ?> 
2
  • I would recommend using css flexbox instead of using tables. Then you can make it responsive by making it wrap and much much more. Here's a pretty extensive guide: css-tricks.com/snippets/css/a-guide-to-flexbox Commented Nov 1, 2017 at 7:02
  • The query is nonsensical so one has to reject the premise of the question Commented Nov 1, 2017 at 7:40

2 Answers 2

1

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>';

?> 
Sign up to request clarification or add additional context in comments.

Comments

0

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> 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.