Problem When printing a SQL query on the PHP page

1

I have a SQl query and my code is printed only the first line of the query, does anyone have any idea what my problem might be?

  

ERROR: Warning: mysql_fetch_assoc () expects parameter 1 to be resource,

<?php 
    include ("conexao.php");
    //$query = "SELECT SUM(valor), pagador from conta GROUP by pagador"
    $consulta = "SELECT SUM(valor) as soma, pagador from conta GROUP by pagador";
    $result = mysqli_query($conexao,$consulta) or die(mysql_error());
    $linha = mysqli_fetch_array($result);
    $total = mysqli_num_rows($result);

    // se o número de resultados for maior que zero, mostra os dados
    if($total > 0) {
        //inicia o loop que vai mostrar todos os dados
        do {
?>
<p><?=$linha['soma']?> / <?=$linha['pagador'];?></p>
<?php
        // finaliza o loop que vai mostrar os dados
        }while($linha = mysql_fetch_assoc($result));
        // fim do if 
     }
    mysql_close($conexao);
?>
    
asked by anonymous 16.10.2015 / 22:39

1 answer

2

See if this helps dear friend:

<?php 
    include ("conexao.php");
    $consulta = "SELECT SUM(valor) as soma, pagador from conta GROUP by pagador";
    $result = mysqli_query($conexao,$consulta) or die(mysqli_error($conexao));

    while($linha = mysqli_fetch_array($result,MYSQLI_ASSOC))
    {
        echo "{$linha['soma']} / {$linha['pagador']}</p>";
    }

    mysqli_close($conexao);
?>

I do not know what's in the connection.php file, so I can not steer it, but I think the code there should be something close to:

<?php $conexao=mysqli_connect("servidor","usuario","senha","banco"); ?>
    
16.10.2015 / 23:22