Mat
Mat

Reputation: 59

Vertical table output

I have this php code:

foreach($output as $row) {      

    $table.="<tr>";
    foreach($row as $column) {
        $table .="<td>";
        $values = implode(",",$column);
        $table .= count($column);   
        $table .="</td>";
    }
    $table.="</tr>";    
}
    
$table.="</table>";
    
echo $table;

This code gives me the results as an horizontal output. Horizontal table

But I need it in vertical position. Like this:

Vertical table

Is it possible to get this result with a simple change?

Note: I couldn't change the direction of the numbers in the second image.

There are more than a single row, so the desired table should be something like this:

sample table

Upvotes: 0

Views: 576

Answers (2)

Hasta Dhana
Hasta Dhana

Reputation: 4719

You could simply include the <tr> inside the foreach loop :


foreach($output as $row) {      

    foreach($row as $column) {
        $table.="<tr>";
        $table .="<td>";
        $values = implode(",",$column);
        $table .= count($column);   
        $table .="</td>";
        $table.="</tr>";    
    }
}
    
$table.="</table>";
    
echo $table;

Upvotes: 1

M. Eriksson
M. Eriksson

Reputation: 13635

If you want one number per row, it should work by moving the tr-pairs inside the loop:

foreach($row as $column) {
    $table .="<tr><td>";
    $values = implode(",",$column);
    $table .= count($column);   
    $table .="</td></tr>";
}

Note: Don't forget to remove your current $table .= "<tr>"; and $table .= "</tr>"; lines.

If you only want the data in one column, you don't really need to use tables. You could just echo the number in div's instead.

Upvotes: 1

Related Questions