A
A
Al Sm2016-03-10 18:32:49
PHP
Al Sm, 2016-03-10 18:32:49

How to pass values ​​from an array to a rendered table?

Hello. I can't figure it out guys, please help!
There is an array with user data (names, avatars, addresses, etc.).
With the following array iteration function, I can call the values ​​of all users:

foreach($users as $q) {
echo get_avatar( $q->ID, 50 );
echo get_the_author_meta('display_name', $q->ID);
}

Standard table rendering:
echo '<table border="1">';
for ($tr=1; $tr<=$rows; $tr++) {
echo '<tr>';
for ($td=1; $td<=$cols; $td++) {
echo '<td>';
echo '</td>';
}
echo '</tr>';
}
echo '</table>';

But I can't figure out how to insert the values ​​of each user separately into a page cell!?
That is, for example, I want to get a table of two columns, each cell should contain information about each user.

Answer the question

In order to leave comments, you need to log in

2 answer(s)
L
look2009, 2016-03-10
@radio_mus

echo '<table border="1">';
$i=0;
foreach($users as $q) {
if($i%2==0)
{
   echo '<tr>';
}
   echo '<td>';
   echo get_avatar( $q->ID, 50 );
   echo get_the_author_meta('display_name', $q->ID);
   echo '</td>';
if($i%2==0)
{
   echo '<tr>';
}
$i++;
}
echo '</table>';

A
Anton Natarov, 2016-03-10
@HanDroid

seems to be so

<table border="1">
<tr>
    <th>Имя</th>
    <th>Фамилия</th>
   </tr>
<?php 
foreach($users as $user) {
  echo '<tr>';
    echo '<td>' . $user->firstname . '</td>';
    echo '<td>' . $user->lastName . '</td>';
 echo '/<tr>';
?>

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question