Bootstrap - .table-striped class does not work correctly within a while

0

I'm using Bootstrap to make a system. At the time of listing the lines of my select using while the rows are not without zebradas correctly, they all come out dark, as if all the rows were the first one of the table (I think that is what Bootstrap is understanding), however the deletion and editing of each line is working perfectly, it's just visual. Here is the snippet of code:

$query = mysql_query(" SELECT * FROM USUARIOS ");
                            echo
                            "<table class='table table-hover table-striped'>
                          <thead>
                                </tr>
                                    <th>Nome</th>
                                    <th>E-mail</th>
                              <th></th>
                                <tr>
                          </thead>
                          <tbody>";
                          while($row = mysql_fetch_array($query)){
                                echo
                                "</tr>
                                <td>".$row['nome']."</td>
                                <td>".$row['email']."</td>
                              <td>
                                <button type='button' class='btn btn-info btn-xs' title='Detalhes' data-toggle='modal' data-target='#modalAlteracaoUsuario' data-whatever-nome='".$row['nome']."' data-whatever-email='".$row['email']."'><i class='fa fa-eye'></i></button>
                                <button type='button' class='btn btn-warning btn-xs' title='Trocar Senha' data-toggle='modal' data-target='#modalAlteracaoSenha' data-whatever-nome='".$row['nome']."' data-whatever-email='".$row['email']."'><i class='fa fa-key'></i></button>
                                <button type='button' class='btn btn-primary btn-xs' data-toggle='modal' data-target='#modalAlteracaoUsuario' data-whatever-id='".$row['id']."' data-whatever-nome='".$row['nome']."' data-whatever-email='".$row['email']."'>Editar</button>
                                <a class='btn btn-danger btn-xs'>Excluir</a>
                              </td>
                                <tr>";
                                }
                            echo
                            "</tbody>
                        </table>";

What can I do to fix this? Thank you!

    
asked by anonymous 23.07.2016 / 17:11

1 answer

0

You're confusing opening tag with closing. To open a tag, use <tag> and to close </tag> .

In your code you were closing a tag and then opening, as in the excerpt:

</tr>
    <th>Nome</th>
    <th>E-mail</th>
    <th></th>
<tr>

It looks like this: (I hid the button code to not get too ugly)

<table class='table table-hover table-striped'>
    <thead>
        <tr>
            <th>Nome</th>
            <th>E-mail</th>
            <th>...</th>
        </tr>
    </thead>
    <tbody>
        <?php
            $c =1;
            $row = array('nome' => 'nome', 'email' => 'email', 'id' => 0);

            echo "<tr>\n";

            while($c < 5)
            {
                echo "\t\t\t<td>".$row['nome']."</td>\n\t";
                echo "\t\t<td>".$row['email']."</td>\n\t";
                echo "\t\t<td><a class='btn btn-danger btn-xs'>Excluir</a></td>\n\t";
                echo "\t</tr>\n\n\t\t<tr>\n";
                $c ++;
            }
            ?>
        </tr>
    </tbody>
</table>

Tip, too much echo in html pure gets ugly, merge HTML with PHP.

Another thing I noticed was that in the while I did not seem to have any notion of what I was doing to open and close lines, so I adapted by putting a logic that I always use in my applications, in the resulting source code you can see that on a line a more ( <tr></tr> ) but does not disturb anything.

To be functional on the PC of any member I put a while without database need, just for example.

Finishing, \n (line break) and \t (tab, famous TAB) used in echo were just to indent the source code in the browser so you can see the structure of a table and can understand better.

    
23.07.2016 / 17:37