how to make Ceil call

Asked

Viewed 54 times

0

How could I fix my code after counting by printing the value for myself 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{

}

that’s the line of error:

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

and my mistake is:

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

  • I don’t understand the question. if you’re just printing the media, do echo $media; she is not an array.

  • Good morning thank you. Well I make the call echo in the <Strong>visits, but do not give me the value.

  • 1

    where the variable $visits ? is declared in one section appears in a mathematical operation and in another it is treated as array.. it makes no sense

  • What I see is $ visitas_total.

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 result set as an associative matrix


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

$media = ceil($visitas['visitas']/$linhas);
  • 1

    Thanks a lot Jeferson Assis, ok! All right.Thanks a lot.

  • Come on, we’re here forever to help, give a upvote where you agree to the answer :), abs.

Browser other questions tagged

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