List table data and assign value to each table (SQL)

0

Good morning! I would like to know how I do to list the data in a table and assign value to each of them! Example:

Table: character Columns: ID and name

I would like to get all the names that have the same id, and list them on a page each with one with the value of its own name! I do not know if it was clear: x I await replies.

    
asked by anonymous 08.03.2015 / 13:26

1 answer

1

Hello, would it be something like this?

$sql = "SELECT id FROM personagens where id_usuario={$id_usuario_logado}";

$sql = mysqli_query($conexao_sqli, $sql);

$id = "";

while($row = mysqli_fetch_object($sql)){
    $id .= $row->id . ",";
}

$id = substr($id, 0 , -1);

$sql = "SELECT usuario FROM personagens WHERE id IN({$id})";

$sql = mysqli_query($conexao_sqli, $sql);

while($row = mysqli_fetch_object($sql)){
    echo $row->usuario ."<br/>";
}
    
08.03.2015 / 14:22