error in mysql_result () [closed]

4

I'm looking for help to understand an error given in a call to mysql_result (), that I can not resolve this error:

  

Warning: mysql_result () expects parameter 1 to be resource, object   given in C: \ wamp \ www \

I do not know what parameter you are asking for.

This is the code:

 <?php 
          $visitas_total = mysqli_query($conexao,"SELECT Sum(visitas) AS visitas FROM lp_post")
                        or die(mysql_error());
       if(@mysqli_num_rows($visitas_total) <= '0') echo '';
       $views = 0;
       $visitas = mysql_result($visitas_total, $views, 'Visitas') ;

         ?>

Could anyone help me?

    
asked by anonymous 22.09.2015 / 21:59

1 answer

5

Use mysqli_fetch_assoc() or _array() to get the query return, do not mix the mysql_ API with the new mysql i .

$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['visitas']; 
} 

If your query returns more than one line, use a while to iterate through all the results.

while($row = mysqli_fetch_assoc($visitas_total)){
    echo $row['visitas'] .'<br>';
}

Recommended reading:

Why do you say that using @ atm to suppress errors is bad practice?

    
22.09.2015 / 22:07