Show View output in PHP

Asked

Viewed 515 times

1

Good night,

I need to show the result of a view I created in Postgres, but I get no return.

View in Postrgres:

 CREATE VIEW VW_RELATORIO03 AS
 SELECT EXTRACT (MONTH FROM DATSOLPED) AS MES, COUNT(*) AS CONTADOR, 
 SUM(VALPED) FROM PEDIDO WHERE DATSOLPED between '01/01/2017' and 
'31/12/2017' GROUP BY MES ORDER BY CONTADOR DESC

Function seeking the report:

function buscaRelatorio03(){
        include("db/conexao.php");
    $comando = $conexao->prepare("SELECT * FROM VW_RELATORIO03");
    //executando o comando
    $comando->execute();
    return $comando;}

Shows the return in a table:

    $lista = buscaRelatorio03();
        if(isset($lista) && $lista->rowCount() > 0){
            echo "<th>MÊS</th>";
            echo "<th>QUANTIDADE TOTAL</th>";
            echo "<th>VALOR TOTAL</th>";
            while($linha = $lista->fetch(PDO::FETCH_ASSOC)){
                echo "<tr>";
                echo "<td>" . $linha["mes"] . "</td>";
                echo "<td>" . $linha["contador"] . "</td>";
                echo "<td>" . $linha["sum"] . "</td>";
                echo "</tr>";   
        }
        }

Obs: month, counter, sum are the fields that return in the view.

No answers

Browser other questions tagged

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