Create HTML table using PHP

5

Can I create a table to separate this code? This is the only way to align the data I have

if($exibe['Nome1'] != NULL) {
    echo '<p><b>Nome: </b>'.$exibe["Nome1"].' &nbsp;&nbsp;<b> Função : </b>'.$exibe["Funcao1"];
}'</p>

<p>';
if($exibe['Nome2'] != NULL) {
    echo '<p><b>Nome: </b>'.$exibe["Nome2"].' &nbsp;&nbsp; <b> Função : </b>'.$exibe["Funcao2"];
}'</p>

I want to put a table like this:

|Nome      | Função   |

|Nome1     | Função1  |

|Nome2     | Função2  |
    
asked by anonymous 10.06.2014 / 11:10

2 answers

7

Just edit the html within your php

<?php
echo '</table>
    <tr>
            <td>Nome</td>
            <td>Função</td>
    </tr>';
if($exibe['Nome1'] != NULL) {
    echo "<tr>
            <td>{$exibe["Nome1"]}</td>
            <td>{$exibe["Funcao1"]}</td>
    </tr>";
}
if($exibe['Nome2'] != NULL) {
    echo "<tr>
            <td>{$exibe["Nome2"]}</td>
            <td>{$exibe["Funcao2"]}</td>
    </tr>";
}
echo '</table>';
    
10.06.2014 / 11:21
0

Friend, if you have a loop, you can do this as follows:

<?php
    echo ' 
        <table>
            <tr>
                <td><b>Nome</b></td>
                <td><b>Função</b></td>
            </tr>
    ';
            while (<< condição >>) {
                if ($exibe['Nome1'] != NULL) {
                    echo '
                        <tr>
                            <td>'.$exibe['Nome1'].'</td>
                            <td>'.$exibe['Funcao1'].'</td>
                        </tr>
                    ';
                }
                if ($exibe['Nome2'] != NULL) {
                    echo '
                        <tr>
                            <td>'.$exibe['Nome2'].'</td>
                            <td>'.$exibe['Funcao2'].'</td>
                        </tr>
                    ';
                }
            }
    echo '
        </table> 
    ';
?>
    
11.06.2014 / 16:18