Field of the table is taken as independent

0

Greetings, I would like you to help me because I want to write the records of a table through a function and what happens is that the id column has added the function that when pressed it takes a text field and the problem is that when you click on this column all the ids in the table go to the text field and I only need the value that you select, this is the function

function Listar($columna){
    include("Conexion.php");

    $consulta="SELECT $columna FROM usuario";
    $resultado=$conexion->query($consulta);

    if(mysqli_num_rows($resultado)>=1){
        while($usuarios=$resultado->fetch_array(MYSQLI_BOTH)){
            $var=$usuarios[$columna];
            echo $var."<br>";
        }
    }else{
        echo "no hay registros para listar";
    }

And so I'm printing it

<td><a href="#" class="name"><?php echo Listar('id_usuario'); ?></a></td> 

I could solve it by printing the data of each user independently since when listing all in the same echo were taken as a single column, this was the way to solve it echo "<tr><td class='name'>".$usuarios['id_usuario']."</td><td>".$usuarios['nombre']."</td><td>".$usuarios['apellido']."</td><td>".$usuarios['telefono']."</td><td>".$usuarios['direccion']."</td><td>".$usuarios['correo']."</td><td>".$usuarios['password']."</td></tr>";

    
asked by Juan David 27.06.2016 в 22:18
source

2 answers

0

In your Listar function, you are precisely browsing in the for all your users.

To solve it (If I have understood your problem well) you do not need any function, you can simply call what you need like this:

echo $usuarios['id_usuario']

Within your table or as you have it defined.

    
answered by 28.06.2016 в 16:59
0

Posted in a comment by the OP:

  

I could solve it in this way by printing a record independently echo "<tr><td class='name'>".$usuarios['id_usuario']."</td><td class='name'>".$usuarios['nombre']."</td></tr>"; } @ Alvaro Montoro thanks

    
answered by 13.04.2017 в 15:00