PHP - Turning a table with values generated by for $ i / for $ j into a variable

3

Good afternoon everyone. I have a form that shows the fields in the form of a table:

echo "<table style='text-align: center; widtd: 280pt;' border='1'>";
    // Cabeçalho da tabela:
    echo '<tr><td>AAA</td><td>BBB</td><td>CCC</td><td>DDD</td><td>EEE</td></tr>';
    for ($i=0; $i<3; $i++){ 
        echo "<tr>"; 
        for ($j=0; $j<4; $j++){            
            if (($i==0) && ($j==0)){
                echo "<td style='text-align: center; widtd: 100pt;'>AA</td>";                 
            }
            if ($i==0) {
                echo "<td><input name='linhaum$j'></td>";
            }

            if (($i==1) && ($j==0)){
                echo "<td style='text-align: center; widtd: 100pt;'>BB</td>";                
            }
            if ($i==1) {
                echo "<td><input name='linhadois$j'></td>";
            }

            if (($i==2) && ($j==0)){
                echo "<td style='text-align: center; widtd: 100pt;'>CC</td>";               
            }
            if ($i==2) {
                 echo "<td><input name='linhatres$j'></td>";
            }            
        }
        echo "</tr>";
    }
    echo "</table><br>";

I'm getting this form this way:

echo '<table style="text-align: center; widtd: 280pt;" border="1">';
    echo '<tr><td>AAA</td><td>BBB</td><td>CCC</td><td>DDD</td><td>EEE</td></tr>';
    for ($i=0; $i<3; $i++){ 
        echo '<tr>';
        for ($j=0; $j<4; $j++){            
            $linhaum = $_POST["linhaum$j"];
            $linhadois = $_POST["linhadois$j"];
            $linhatres = $_POST["linhatres$j"];

            if (($i==0) && ($j==0)){
                echo '<td style="text-align: center; widtd: 100pt;">AA</td>';                 
            }
            if ($i==0) {
                echo "<td>$linhaum</td>";
            }

            if (($i==1) && ($j==0)){
                echo '<td style="text-align: center; widtd: 100pt;">BB</td>';                
            }
            if ($i==1) {
                echo "<td>$linhadois</td>";
            }

            if (($i==2) && ($j==0)){
                echo '<td style="text-align: center; widtd: 100pt;">CC</td>';               
            }
            if ($i==2) {
                 echo "<td>$linhatres</td>";
            }            
        }
        echo '</tr>';
    }
echo '</table><br>';

What I need: Convert this table, already populated with the captured data, into a variable.

Example of what I need:

$minhavar = "a tabela que foi preenchida com os valores do formulário";
[...];
echo $minhavar;

Thank you!

    
asked by anonymous 26.02.2017 / 22:29

1 answer

2

Thank you, however, I already got the solution:

$equipe = '<table style="text-align: center; widtd: 280pt;" border="1">';
    $equipe .= '<tr><td>AAA</td><td>BBB</td><td>CCC</td><td>DDD</td><td>EEE</td></tr>';
    for ($i=0; $i<3; $i++){ 
        $equipe .= '<tr>';
        for ($j=0; $j<4; $j++){            
            $linhaum = $_POST["linhaum$j"];
            $linhadois = $_POST["linhadois$j"];
            $linhatres = $_POST["linhatres$j"];

            if (($i==0) && ($j==0)){
                $equipe .= '<td style="text-align: center; widtd: 100pt;">AA</td>';                 
            }
            if ($i==0) {
                $equipe .= "<td>$linhaum</td>";
            }

            if (($i==1) && ($j==0)){
                $equipe .= '<td style="text-align: center; widtd: 100pt;">BB</td>';                
            }
            if ($i==1) {
                $equipe .= "<td>$linhadois</td>";
            }

            if (($i==2) && ($j==0)){
                $equipe .= '<td style="text-align: center; widtd: 100pt;">CC</td>';               
            }
            if ($i==2) {
                 $equipe .= "<td>$linhatres</td>";
            }            
        }
        $equipe .= '</tr>';
    }
$equipe .= '</table><br>' ;

echo $equipe;
    
26.02.2017 / 23:12