Show View result in PHP

1

Good evening,

I need to show the result of a view I created in Postgres, but I do not get any feedback.

View on 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

Report fetched function:

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

Show 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>";   
        }
        }

Note: mes, counter, sum are the fields that return in the view.

    
asked by anonymous 14.11.2017 / 00:00

0 answers