Jump to content
Larry Ullman's Book Forums

sql issues that are not addressed


Recommended Posts

Would you know how to extract the number of user that is in a particular table?

$q = "SELECT COUNT(user) FROM table1 WHERE user = 'glenn'";
$r = @mysqli_query($dbc, $q);
//$num = mysqli_num_rows($r);
//$id = mysqli_fetch_field($r);
//$id = mysqli_fetch_array($r);
$id = mysqli_fetch_assoc($r);

echo 'r user number '. $r .'<br>';
echo 'n user number '. $num .'<br>';
echo 'n user number '. $id .'<br>';


I get different errors BUT no result!

Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, boolean given in

Warning: mysqli_fetch_array() expects parameter 1 to be mysqli_result, null given in

Thank you much.

Link to comment
Share on other sites

Instead giving me some warnings, shouldn't it tell me it is not connected to DB! I believe that what it did before, my old setup, I guess something changed that is different from the old. Sorry for bugging you with details.

Link to comment
Share on other sites

If you remove the error suppression operator, you'll see the error messages. You should probably also use some conditionals in there, such as checking that mysqli_num_rows() returns 1 or more records before you attempt to fetch them.

Link to comment
Share on other sites

 Share

×
×
  • Create New...