How can I hide information in php?

Asked

Viewed 40 times

-2

I have the following structure

    $tabDados = "<table id='cabTabela' border='3'>
            <tr>
                <td id='cabCelula'> <br>nome completo</td>           
                <td id='cabCelula'> <br>numero de telefone </td>            
                <td id='cabCelula'> <br>endereco</td>
                <td id='cabCelula'> <br>Data da movimentação </td>
                <td id='cabCelula'> <br>Dias parados </td>
            </tr>
        </table>";


    $tabDadosMov .= "<table id='movTabela' border='3'>
            <tr>
                <td id='movCelula'> <br>$nome</td>           
                <td id='movCelula'> <br>$numero</td>            
                <td id='movCelula'> <br>endereco</td>
                <td id='movCelula'> <br>$data_inicial</td>
                <td id='movCelula'> <br>$tempoParado</td>
            </tr>
        </table>";

I would like to show the second table only if the user clicks on the "display data".

I saw that you can do with the display: None css, but I could not because it is a variable

  • 2

    Putting display: none: doesn’t work? --> $tabDadosMov .= "<table id='movTabela' border='3' style="display: none;">. Actually you will not be hiding by PHP, but by CSS. I believe you need to understand more basic notions of programming.

  • "ocular"? I think I should read the website guidelines at [Ask].

  • I tried, but for some reason it didn’t work. I’m trying another alternative, thank you very much >:)

  • it worked, thank you very much, I had tried, but for some reason the css application fails sometimes, and to fix I have to change the name of the css file, I haven’t figured out the reason why

1 answer

0

For the content to be displayed from a button click on, you can use the display: none (CSS) and assign a function in Javascript that changes this display as you click and the current state of the table, such as the example below (origin):

function mostrar_ocultar(id) {
  var x = document.getElementById(id);
  if (x.style.display === "none") {
    x.style.display = "block";
  } else {
    x.style.display = "none";
  }
}
<table id='cabTabela' border='3'>
  <tr>
    <td id='cabCelula'> <br>nome completo</td>           
    <td id='cabCelula'> <br>numero de telefone </td>            
    <td id='cabCelula'> <br>endereco</td>
    <td id='cabCelula'> <br>Data da movimentação </td>
    <td id='cabCelula'> <br>Dias parados </td>
  </tr>
</table>

<button onclick="mostrar_ocultar('movTabela')">Exibir Dados</button>

<table id='movTabela' border='3' style="display: none;">
  <tr>
    <td id='movCelula'> <br>$nome</td>           
    <td id='movCelula'> <br>$numero</td>            
    <td id='movCelula'> <br>endereco</td>
    <td id='movCelula'> <br>$data_inicial</td>
    <td id='movCelula'> <br>$tempoParado</td>
  </tr>
</table>

But importantly, this way brings the PHP data to HTML and leaves it hidden initially, IE, the user can see the table data inspecting the page.

This way, this is not the way if you need to do some server-side validation. It would be the case to check if the user is logged in to the system, for example. In this case, for security, you would make a condition within PHP so that it wouldn’t even send the HTML data to the user.

  • Got it, thank you very much, I will try to do it here, actually I just want to hide to make the screen more "clean" so the user can go only on what interests him and click to display

  • If it is for the layout, can do as the example I posted above, no problems. Keeps the PHP code as it is, just adding the display: None and puts the function js.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.