Display of personal data in a table

Asked

Viewed 47 times

0

Good morning I would like to know how to display only my name that is in the database instead of displaying everything in a table.

public Function all(){

    $sql = $this->con->prepare("SELECT * FROM usuario");
    $sql->execute();
    $rows = $sql->fetchAll(PDO::FETCH_CLASS);

    if (!$rows) {
        $_SESSION['cor']='danger';
        $_SESSION['msg'] = "<b>Nenhum usuário cadastrado</b>";
    }

    return $rows;
}

Not if I use the "WHERE id" or if you have another easier way.

  • If you use "Where id" you will restrict the record only with the given id.

1 answer

1


Create another function to grab the user by ID.

public function by_id($id_user){
    $sql = $this->con->prepare("SELECT * FROM usuario WHERE id = ".$id_user);
    $sql->execute();
    $row = $sql->fetch(PDO::FETCH_CLASS);

    if (!$row) {
        $_SESSION['cor']='danger';
        $_SESSION['msg'] = "<b>Nenhum usuário cadastrado</b>";
    }

    return $row;
}

Browser other questions tagged

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