Well, here it is, usually problematic part of code is like:
$query = mysqli_query($conn, 'SELECT COUNT(`id`) FROM `table` WHERE `id` = '.$id.'');
$count = mysqli_num_rows($query);
... which is throwing error:
PHP Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in /www/user/public_html/index.php on line 2
... so the query must be in if():
if ($query = mysqli_query($conn, 'SELECT COUNT(`id`) FROM `table` WHERE `id` = '.$id.'')) {
$count = mysqli_num_rows($query);
}
But this is throwing this error:
PHP Notice: Undefined variable: count in /www/user/public_html/index.php on line 2
... so simple define it:
// 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);
}
And there will be no Warning nor Notice. 🙂
<!DOCTYPE html PUBLIC "-//***WAPFORUM**.**RS***