1
How to list all the data of this query, I can only show the first line but I want to query all and show them.
public function gerarCardapio(){
try{
$cat = "M";
$sql = "SELECT * FROM alimentos WHERE id_usuario = :idUser AND categoria = :cat AND quantidade >0 ";
$stmt = DB::prepare($sql);
$stmt->bindParam('idUser', $_SESSION['user_id']);
$stmt->bindParam('cat', $cat);
$stmt->execute();//Executa o comano SQL
$result = $stmt->fetch(PDO::FETCH_ASSOC);
echo $stmt->rowCount();
}catch (PDOException $e){
echo $e->getMessage();
}
}
In the code, I don’t see where you’re returning or printing the result on the screen, other than the number of lines that were returned
echo $stmt->rowCount();
– NoobSaibot
The documentation is your friend, see example #2: http://php.net/manual/en/pdostatement.fetch.php#example-1058
– Guilherme Nascimento