How to get select (MYSQL) data and display in different fields?

0

Good morning !! The B is as follows:

I have my select in php where I get the data from the table, I wanted to know how I can separate and display this data individually.

Ex: SELECT nome_cliente, idade_cliente From tb_cliente WHERE COD_cliente={$x}

This query will return only one line, so I wanted to get these

results and put each one in a variable so you can get the name and

put in the value of one input and the age in the value of another.

    
asked by anonymous 13.06.2017 / 16:38

1 answer

0

I recommend that you connect to Mysql using the PDO class, as shown below:

<?php

$server = "localhost";
$database = "test";
$user = "usuario";
$pass = "senha";

try {
    $dbh = new PDO('mysql:host='. $server . ';dbname=' . $database, $user, $pass);
    foreach($dbh->query('SELECT nome_cliente, idade_cliente From tb_cliente WHERE COD_cliente={$x}') as $row) {
        echo '<input type="text" name="nome" value="' . $row["nome_cliente"] . '"><br>';
        echo '<input type="text" name="nome" value="' . $row["idade_cliente"] . '"><br>';
    }
    $dbh = null;
} catch (PDOException $e) {
    print "Error!: " . $e->getMessage() . "<br/>";
    die();
}
    
13.06.2017 / 17:34