I'm trying to get the number of records in my database as an integer and use it in PHP to set certain conditions. My code consists of the following:
$sql = "SELECT COUNT(id) FROM sql_table";
$records = $conn->query($sql);
$record_count = $records->fetch_assoc();
I did a var_dump
of $record_count
and it returned an array: array(1) { ["COUNT(id)"]=> string(1) "4" }
. What I can't do is just access the number 4. I can access string(1) "4"
by accessing $record_count['COUNT(id)']
, but I can't find a way to access the number 4. If I try indexing, as in $record_count['COUNT(id)'][11]
, I get nothing. This value does not appear to be a straight string.
How can I access the number of records in the table as an integer for use in PHP?