Mysqli依靠php“无法将mysqli_result类型的对象用作数组”

时间:2018-08-08 02:38:37

标签: php arrays mysqli count

我想用mysqli做一个简单的值计数。我有

    $qnt = "SELECT COUNT(usu_nome) FROM esc_usuarios WHERE usu_indicador_codigo = '" . $_SESSION['codigo'] . "'";
    $qntresul = mysqli_query($conexao, $qnt);
    $colunaqnt = mysqli_fetch_array($qntresul);

但是我收到了:

  

致命错误:未捕获错误:无法将mysqli_result类型的对象用作数组

我正在用echo $qntresul['usu_nome']打电话 有想法吗?

1 个答案:

答案 0 :(得分:0)

Try this ,  will work fine   

 $qnt = "SELECT COUNT(usu_nome) as 'total' FROM esc_usuarios WHERE usu_indicador_codigo = '" . $_SESSION['codigo'] . "'";
            $qntresul = mysqli_query($conexao, $qnt);
            $colunaqnt = mysqli_fetch_array($qntresul);
    echo $colunaqnt['total'];