-1

There is a table 'hit_count' containing only one column 'count' in database in which I am trying to count the hits by user. problem is whenever I am running this code it shows an error message "Fatal error: Call to undefined function mysqli_result()". Please help!!

<?php
error_reporting(E_ALL);
ini_set('display_errors', 1);

require 'connect.inc.php';

function update_count()
{
    global $link;
    $query = "SELECT `count` FROM `hit_count`";
    if($query_run = mysqli_query($link,$query) || die(mysqli_error($link)))
    {       
        echo 'checking control';
        $count = mysqli_result($query_run,0,'count');
        echo $count;            
    }
    else
    {
        echo 'Problem Occured!!';
    }
}
update_count();
?>

1 Answers1

0

There isn't a mysqli_result function (not that you can't define it, but what for?). There is a mysqli_result Class, and it has static methods that you can call, of course. But I believe you're doing this wrong.

The correct way would be something like

$count=array();
if($query_run = mysqli_query($link,$query) || die(mysqli_error($link)))    {       
    while ($row = $query_run->fetch_array(MYSQLI_ASSOC)) {
      $count[]=$row["count"];
    }
}

remember that the outcom of mysqli_query will be an iterable object. Don't expect it to return an aggregate value by default.

PD: if you name your columns with reserved words like count, you're gonna have a bad time.

ffflabs
  • 17,166
  • 5
  • 51
  • 77