0

I am trying to create this simple if statement, but I am running into issues with the variable $testnumrows. In this if condition I am trying to see if there are any group columns with data and if so echo the amount of rows, but I want nothing to show up if there isn't.

In my db I have 6 rows that have what I mentioned in the query. The output that is showing up on the page is 0 though, so it seems my variable is being reset.

Before I had this:

$testnumrows = mysqli_num_rows($test);
echo " " . $testnumrows;

and it read the 6, I just can't get the if statement to work.

Here is the full code now.

<?php
$con = mysqli_connect("localhost", "", "", "");
$test = mysqli_query($con,"SELECT `group` FROM user_requests WHERE `group` = 1");
$testnumrows = mysqli_num_rows($test);

if($testnumrows = 0) {
echo "";
} else {
echo " " . $testnumrows;
}
?>
Becky
  • 2,283
  • 2
  • 23
  • 50

3 Answers3

1

Trivial error = instead of == Solution:

if($testnumrows == 0) {
echo "";
} else {
echo " " . $testnumrows;
}
Kyborek
  • 1,519
  • 11
  • 20
1

It should read if($testnumrows == 0) {.

syck
  • 2,984
  • 1
  • 13
  • 23
1

Change if($testnumrows = 0) to if($testnumrows == 0).

thewisegod
  • 1,524
  • 1
  • 10
  • 11