I'm trying to get the total number of rows in a table using this code:
$count = mysqli_query($con, "SELECT COUNT(*) AS total FROM random_codes");
$count = mysqli_fetch_object($count);
$count = $count->total;
echo "count is $count<br />";
but the echo is always "count is " with no value following. Runing the same SQL code in phpMyAdmin returns the number of rows (above 2000) as total like requested, so the problem is probably in the php code. Dear responders, I'm new to php & sql so please elaborate and/or link me to documentation. Thanks..
EDIT: attempted error checking, no error shows
$result = mysqli_query($con, "SELECT COUNT(*) AS total FROM random_codes");
echo mysqli_error($con);
$obj = mysqli_fetch_object($result);
$count = $obj->total;
echo "count is $count<br />";