mysqli_fetch_array always returns 99


mysqli_fetch_array always returns 99



I have 103 records in table catalogue, however when I run the following function:


catalogue


$db_table = '`catalogue`';
$db_table_id_field = 'catalogue.ID';

private function countNumRows($db_table,$db_table_id_field){
$where_condition = $this->whereClause(); // is empty string
$this->sql = "
SELECT COUNT($db_table_id_field) AS count_r
FROM $db_table
$where_condition;
";

/* SELECT COUNT(catalogue.ID) AS count_r
FROM `catalogue`
; - this query returns 103 */

$this->result = mysqli_query($GLOBALS["___mysqli_ston"], $this->sql) or die($this->error = mysqli_error($GLOBALS["___mysqli_ston"]));
$row = mysqli_fetch_array($this->result,MYSQLI_BOTH);
return $row[0];// returns count of 99 rows!WHY????????????
}



I only get 99 records. I also tried mysqli_fetch_array($result, MYSQLI_ASSOC); and mysqli_fetch_array($result, MYSQLI_NUM); with the same result.


mysqli_fetch_array($result, MYSQLI_ASSOC);


mysqli_fetch_array($result, MYSQLI_NUM);



I have also checked if there are less than 99 records, it still returns 99.
Any ideas?





maybe null values in catalogue.ID ?
– FatFreddy
Jun 29 at 10:50





@FatFreddy no, it'd autoincrement
– Elen
Jun 29 at 10:51


autoincrement





Silly question, but are you absolutely sure you're connecting to the same copy of your database? It would be an obvious reason for such a discrepancy
– ADyson
Jun 29 at 10:53





She says that running the query without variables returns 103, so seems to be the correct/same DB. The only difference is using variables in the query string.
– BigMeat
Jun 29 at 10:55






Did you run the query directly on MySQL, to ensure the number of records it returns?
– Penguine
Jun 29 at 10:55









By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Comments

Popular posts from this blog

paramiko-expect timeout is happening after executing the command

how to run turtle graphics in Colaboratory

Export result set on Dbeaver to CSV