how to call ceil

0

How could I fix my code after counting the value for me and then splitting it? I'm a beginner in php.

$sql = "SELECT Sum(visitas) AS visitas FROM lp_post";
$visitas_total = mysqli_query($conexao,$sql) or die(mysqli_error($conexao));

if(mysqli_num_rows($visitas_total) <= 0){
    echo 'Nenhum resultado foi econtrado';
}else{
    $visitas = mysqli_fetch_assoc($visitas_total);
    echo ''; 
}

$visitas_media = mysqli_query($conexao,"SELECT id FROM lp_post")or die(mysqli_error($conexao));

$linhas = mysqli_num_rows($visitas_media);
if($linhas >= '2'){
    $media = ceil($visitas/$linhas);
}else{

}

this is the error line:

$media = ceil($visitas/$linhas);

and my error is:

  

Fatal error: Unsupported operand types in C: \ wamp \ www.

    
asked by anonymous 23.09.2015 / 06:02

1 answer

2

The mysqli_fetch_assoc returns a array of results.

PHP Documentation

  

(PHP 5)

     

mysqli_result :: fetch_assoc - mysqli_fetch_assoc - Get a line from the   result set as an associative array

The error you are having is because the split operation does not support array , in this case you would have to do the division like this:

$media = ceil($visitas['visitas']/$linhas);
    
23.09.2015 / 19:57