How to display user data on a page via ID?

0

I'm developing a site where the administrator can view the cadastral data of all the users that are registered in the system, and this data is displayed in a table. The table only displays some data (id, name and email) and I want to make a link where the administrator can click to see the complete information of the selected user. For example, if he clicks the "see more" link of the user with ID 1, the screen displays all his data (id, name, rg, cpf, email, date of birth).

My code for now is this:

<?php 
    $consulta = "SELECT * FROM adms";
    $con = mysqli_query($con, $consulta) or die (mysqli_error);
?>
<table border="1" cellpadding="25px;">
    <tr>
        <td>ID</td>
        <td>Nome</td>
        <td>E-mail</td>
        <td></td>           
    </tr>
    <?php while($dado = $con->fetch_array()){ ?>
        <tr>
            <td><?php echo $dado['id'] ?></td>
            <td><?php echo $dado['nome'] ?></td>
            <td><?php echo $dado['email'] ?></td>
            <td><a href="adm_vermaisAdm.php?id='$dado[id]'">Ver mais</a></td>
        </tr>
    <?php } ?>
</table>

The table looks like this:

Mymainquestionsare:

1)Isthe<ahref="adm_vermaisAdm.php?id='$dado[id]'">Ver mais</a> line declared in the right way? I am in doubt because of the given $ [id], I do not know if it will work that way.

2) To create the data display page, its name would be adm_vermaisAdm.php? id = '$ given [id]'?

3) To display this data, how do I get the URL ID?

Thank you all for responding

    
asked by anonymous 08.12.2018 / 13:27

1 answer

0

Oops! it's OK? I think I can help you. In the order of doubt:

First doubt

The way it is written will not work. Remember that the <a> tag is HTML and that to interpolate php data in your declaration, you must again open the php tag. Here's an example:

<a href="adm_vermaisAdm.php?id='<?php echo $dado['id']?>'">Ver mais</a>

This will already ensure that your anchor is pointing to the page "adm_vermaisAdm.php", passing in the url the id parameter, with a value equal to what is stored in the given variable $ 'id'.

Second doubt

The answer is no! The page (php file) that you are pointing at the anchor is "adm_vermaisAdm.php" and this is how the file should be named.

adm_vermaisAdm.php

Third question

To get the id that came from your URL, you can do the following:

<?php $id = $_GET['id']; ?> 

So you will already have the id to perform the query on and display all the data related to it.

I hope I have helped: D!

    
08.12.2018 / 13:55