-1

I want to compare the result for count(*) with INT. This is my code;

 $sql_check = "SELECT COUNT(*) FROM hd";
 $result_check = mysqli_query($link, $sql_check) or die ("ERR");

 $row = mysql_fetch_assoc($result_check);
 if($row == 1)
 {...}

It seem like there is no error. I tried to run it but it skip my if statement. If I tried to

echo $row

It show error

NOTICE: Array to string conversion

If I used code

 $sql_check = "SELECT COUNT(*) FROM hd";
 $result_check = mysqli_query($link, $sql_check) or die ("ERR");

 $row = int($result_check);
 if($row == 1)
 {...}

It show error

NOTICE: Object of class msqli_result could not converted to int

I have tried to used the answers from previous questions that have been asked before this (same question) but it doesn't work. Can you help me? Please I really need to know where my false.

Thankyou for helping.

Some other questions (that have been asked) and I have tried it but it seem does not work for me: 1. Object of class mysqli_result could not be converted to int and all entries return true 2. mysqli_result could not be converted to int in 3. Object of class mysqli_result could not be converted to int - Can't find my Error 4. Convert SQL query object into integer

Izzati
  • 35
  • 7

1 Answers1

0

you can try this, not sure if it solves the problem!

   $sql_check = "SELECT COUNT(*) FROM hd as 'res'";
     $result_check = mysqli_query($link, $sql_check) or die ("ERR");

     $row = mysql_fetch_assoc($result_check);
     if($row['res'] == 1)
     {...}

OR YOU CAN TRY THIS

 $sql_check = "SELECT COUNT(*) FROM hd as 'res'";
 $result_check = mysqli_query($link, $sql_check) or die ("ERR");

 $row = mysql_fetch_assoc($result_check);
 if((int)$row['res'] == 1)
 {...}
Ashraf D. Milhim
  • 80
  • 1
  • 1
  • 7
  • I have tried your answers. It seem there no any error. But why it still not read my error message in the if statement? But if i put echo in that if & else statement, it show the output for both statement and does not check the condition at if statement. Do you know why? @Ashraf D. Milhim – Izzati Jul 05 '17 at 03:12
  • Oh nvm. I have try to use another way to popup and it work with your code. Thankyou for helping @Ashraf D. Milhim – Izzati Jul 05 '17 at 03:48