4

I have problem with mysqli_result() -> (ex mysql_result)

My code:

$per_page = 6;
$pages_query = mysqli_query($conn, 'SELECT COUNT(id) FROM users');  
$pages = ceil(mysqli_result($pages_query, 0) / $per_page);

browser error:

Fatal error: Call to undefined function mysqli_result() in /Applications/MAMP/htdocs/bootstrap/pagination.php on line 11

Dharman
  • 30,962
  • 25
  • 85
  • 135
Denis Milosavljevic
  • 365
  • 4
  • 8
  • 17

1 Answers1

4

As opposed to mysql_result(), there's no mysqli_result() function available in MySQLi.

Use mysqli_fetch_array() function to get the total number of rows. Your code should be like this:

$per_page = 6;
$pages_query = mysqli_query($conn, 'SELECT COUNT(id) FROM users'); 
$row = mysqli_fetch_array($pages_query);
$pages = ceil($row[0] / $per_page);
Dharman
  • 30,962
  • 25
  • 85
  • 135
Rajdeep Paul
  • 16,887
  • 3
  • 18
  • 37