Answer the question
In order to leave comments, you need to log in
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);
}
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>';
Answer the question
In order to leave comments, you need to log in
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>';
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 questionAsk a Question
731 491 924 answers to any question