0

I am having a problem with my code.

We all know mysql_result is deprecated. So what I've done is created a similar function to replace mysql_result with mysqli_result. My code is shown below.

function mysqli_result($result, $row, $field = 0) {
    $result->data_seek($row);
    $data = $result->fetch_array();

    return $data[$field];
}

Use this code if you need to for your own projects, it works perfect on almost all my pages. On-topic, on some of my pages which uses mysqli_connect, I'm getting an error.

Fatal error: Call to a member function data_seek() on boolean in ... on line 4

Then we have line 4, which is

    $result->data_seek($row);

I'm asking you nicely, how can I adjust my code so it does not give this error anymore? Or maybe dump the code so it doesn't appear anymore.

I've also tried looking up the error on Google, it didn't gave me any answers really.


EDIT: Give us source code where you are calling the function.

if(mysqli_result(mysqli_query($GLOBALS["___mysqli_ston"], "SELECT COUNT(id) FROM downloads"),0) == 0) {
    echo 'No downloads were added.';
}
Carl
  • 23
  • 6
  • How did you fetch `$result` resource? Please give us source code where you are calling this function. – mitkosoft Feb 29 '16 at 12:25
  • @mitkosoft Hey mitkosoft, I have added the desired code. – Carl Feb 29 '16 at 12:31
  • Sidenote: It's usually not a great idea to overrule default functions with your own implementation under the same name. To avoid confusion (for yourself and others) in the future, it's best to name it something like `custom_mysqli_result`. – Oldskool Feb 29 '16 at 12:35
  • @Oldskool That's true, I'll keep that in mind. Thanks! – Carl Feb 29 '16 at 12:37

0 Answers0