mysqli_num_rows doesn't show desired results

mysqli_num_rows not working
mysqli_num_rows returns 0
mysqli_num_rows returns null
mysqli num_rows not working
mysqli num_rows object oriented
mysqli_num_rows() expects parameter 1
count number of rows in mysql php

I have a 'users' table in my Database (currently 4 users) that contains different roles (1 = user, 2= admin, 3= moderator). I want to show some lines of my php script only to admins and moderators, so I made this query: (I know it is not secure)

$conn = mysqli_connect($dbhost, $dbuser, $dbpass, $dbname);
$stuff = 'SELECT * FROM `users` WHERE role > 0';
$result = mysqli_query($conn, $stuff);

This query list all users with the role over 0.

if (mysqli_num_rows($result) >1){
echo "Admin area";
echo "No Permissions";

This should be self explaining (only show "Admin area" to users with role higher than 1)

I don't know what my mistake is and I hope someone could help me a little bit :)

You can use IN in your SQL Query, For example if you need admin and moderator use the following

 SELECT * FROM `users` WHERE role IN ('2','3')

mysqli_num_rows returning number of rows in result set.

if (mysqli_num_rows($result)){
   echo "Admin and moderator area";
  echo "No Permissions";

mysqli_result::$num_rows - Manual, mysqli_result::$num_rows -- mysqli_num_rows — Gets the number of rows in a result doesn't work with LIMIT used jointly with SQL_CALC_FOUND_ROWS. Retorna el número de filas del resultado. El comportamiento de mysqli_num_rows() depende de si es que se utilizan resultsets con o sin buffer. En caso de emplearlos sin buffer mysqli_num_rows() no retornará el número de filas correcto hasta que todas las filas del resultado hayan sido recuperadas.

You are saying you want more than 1 row, you probably want to say more than 0 rows or just 1 row...

if (mysqli_num_rows($result) >1){

Should be

if (mysqli_num_rows($result) >0){


if (mysqli_num_rows($result) == 1){

As for I know it is not secure - as there are no bound parameters, the SQL cannot be influenced by any input and so there is not problems with security in this case. BUT you will probably want to add in the logged in user at some point, this should be done with prepared statements.

PHP, PHP | mysqli_num_rows() Function � Syntax: � Parameters: This function accepts single parameter $result (where $result is a MySQL query set up� mysqli_num_rows() - Is not working. Ask Question Asked 5 years, 9 months ago. Active 5 years, 9 months ago. Viewed 3k times -2. I have a form that takes a users email

I'am grabing the current user now with:

$userID = $page->users->currentUserId();
$stuff = 'SELECT role FROM `users` WHERE id = $userID';
$result = mysqli_query($conn, $stuff;
if (mysqli_num_rows($result) >2){

Grabbing of the current userID is working but how can i compare it with the the role, that is needed ?

In PHP, why doesn't mysqli_num_rows return an , 问题: I am having a strange issue with mysqli_num_rows. Searching for this issue , I've only found people having issues where NULL is� The behaviour of mysqli_num_rows depends on whether buffered or unbuffered result sets are being used. For unbuffered result sets, mysqli_num_rows will not return the correct number of rows until all the rows in the result have been retrieved.

mysqli_num_rows help! : PHP, Using (!mysqli_num_rows($query)) doesn't seem like the right way to test so I tried it with what the internet was suggesting. Which is this: $query = "SELECT� PHP - Function MySQLi Num Rows - It returns the number of rows in a result set

Query returning results when database table is empty - PHP, mysqli_num_rows is correct but it doesn't work well with SELECT COUNT(*). It does work perfectly well, as long as you accept that you will� Well organized and easy to understand Web building tutorials with lots of examples of how to use HTML, CSS, JavaScript, SQL, PHP, Python, Bootstrap, Java and XML.

mysqli_num_rows Code Example, Get code examples like "mysqli_num_rows" instantly right from your google Your browser does not currently recognize any of the video formats available. The mysqli_num_rows() function is an inbuilt function in PHP which is used to return the number of rows present in the result set. It is generally used to check if data is present in the database or not.

  • If all you need is a count then do a COUNT()
  • This seem to be a logical error: You asks for the number of entries, and not about the content of role. So fi there are >=1 user with role>1, all become admin.
  • You also need to check that the current logged in user has that rank. Not just any user of role > 0.
  • @Wimm i thought something like that but i dont know how i could fix this
  • Please don't add further details as an answer - you will either need to add this to the question or ask a new question. BUT you have 2 problems with this code - missing ) in $stuff; - $stuff); and you would expected 1 row - so ($result) >0){ As in my answer - you need to check the number of rows and I wouldn't expect more than 1 row per user (especially not > 2)