Call to Undefined Function MySQLi_Result::Num_Rows()

Fatal error: Call to undefined method mysqli::num_rows()

That's not how that function is used. First you execute your query and then you check to see how many rows were returned from the returned result object:

$result = $mysqli->query("SELECT * FROM `user_bans` WHERE `banned_id` = '".$email."' LIMIT 1");
if($result->num_rows > 0){
return true;
}

Call to undefined function mysqli_result::num_rows()

From the manual, it seems that mysqli_result::num_rows isn't a function, but rather a variable containing the number of rows.

It can be used like this:

$num_rows = $mysqli_result->num_rows;

The function equivalent is mysqli_num_rows($result), where you pass in the mysqli_result object, but that's if you're using the procedural style rather than object oriented style.

In your code, you should change your count() function in the utils_MysqlImprovedResult class to be like this (I'm assuming that's the function where you're getting the error message),

public function count()
{
// Any other processing you want
// ...
return $this->_result->num_rows;
}

or alternatively if you want to mix OO and procedural styles (probably a bad idea),

public function count()
{
// Any other processing you want
// ...
return mysqli_num_rows($this->_result);
}

syntax error Call to undefined method mysqli::num_rows()

Try this -

$q2 = $mysqli->query('SELECT COUNT(id) FROM images');
$numRows = $q2->num_rows;

and

$cueri = $mysqli->query('SELECT COUNT(id) FROM `usuarios` WHERE `last_active` > \''.$is_online.'\'');
$numRowsNew = $cueri->num_rows;

$mysqli_result->num_rows;

Fatal error: Call to undefined function mysqli_result()

Don't use this kind of code. It's highly inefficient. Use mysqli_fetch_assoc() instead:

while($row = mysqli_fetch_assoc($result)) {
$id = $row['ID'];
$name = $row['name'];
etc..
}

One SINGLE database operation, rather than the 3+ you're trying to do.

Fatal error: Call to undefined method mysqli::num_rows()

That's not how that function is used. First you execute your query and then you check to see how many rows were returned from the returned result object:

$result = $mysqli->query("SELECT * FROM `user_bans` WHERE `banned_id` = '".$email."' LIMIT 1");
if($result->num_rows > 0){
return true;
}

Fatal error: Call to undefined method mysqli_result::rowCount()

Use num_rows

Read MySQLi row_count

So final answer would be

function getItems($id = null)
{
if(isset($_GET['id']))
{
$query = $this->link->query("SELECT * FROM items WHERE id = '$id'");
}
else
{
$query = $this->link->query("SELECT * FROM items");
}
$rowCount = $query->num_rows;//change here
if($rowCount >= 1)
{
$result = $query->fetchAll();
}
else
{
$result = 0;
}
return $result;
}

EDIT 01

use mysqli_fetch_all instead of fetchAll()

mysqli_fetch_all($query,MYSQLI_ASSOC);

so answer world be

    if($rowCount >= 1)
{
$result = mysqli_fetch_all($query,MYSQLI_ASSOC);
}

Mysqli num_rows( ) returning undefined property

you should assign the result of the query and then get the count :

<?php
require 'connections.php';
$result = $con->query("SELECT users, UserID from users");
// $result is a mysqli_stmt
$totalplayers = $result->num_rows;
?>

Reference: http://php.net/manual/en/mysqli-stmt.num-rows.php



Related Topics



Leave a reply



Submit