Well, here it is, usually problematic part of code is like:
... which is throwing error:
... so the query must be in if():
But this is throwing this error:
... so simple define it:
And there will be no Warning nor Notice.
PHP Code:
$query = mysqli_query($conn, 'SELECT COUNT(`id`) FROM `table` WHERE `id` = '.$id.'');
$count = mysqli_num_rows($query);
Code:
PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /www/user/public_html/index.php on line 2
PHP Code:
if ($query = mysqli_query($conn, 'SELECT COUNT(`id`) FROM `table` WHERE `id` = '.$id.'')) {
$count = mysqli_num_rows($query);
}
Code:
PHP Notice: Undefined variable: count in /www/user/public_html/index.php on line 2
PHP Code:
// if you want integer:
$count = (int)''; // perfectly valid way
// if you want string:
$count = '';
// or use settype(): http://php.net/manual/en/function.settype.php
settype($count, 'int');
if ($query = mysqli_query($conn, 'SELECT COUNT(`id`) FROM `table` WHERE `id` = '.$id.'')) {
$count = mysqli_num_rows($query);
}