Posts

Showing posts with the label pagination

How to debug php/MySQL COUNT(id) returning 1 instead of total entries value

How to debug php/MySQL COUNT(id) returning 1 instead of total entries value I need the total number of entries in my database. Question: Why does the line "print_r($rows)" return "Array ( [COUNT(id)] => 79 )" but then the line "$recordCount = Count($row); echo " record count = " . $recordCount;" returns "record count = 1". I've tried a massive amount of different versions of this code, but I cant type them all here or it would take forever to read. Here is the current version of the code, which is giving me the unexpected results I mention above: // create connection $conn = new mysqli($servername, $username, $password, $dbname); // check connection if ($conn->connect_error) { die("connection failed: " . $conn->connect_error); } $sql = "SELECT * FROM games ORDER BY id DESC LIMIT $startRow, $rowsPerPage"; $result = $conn->query($sql); $sql = "SELECT COUNT(id) FROM games"; $results = $conn-...