I have a table that has 2 columns. How can I count how many rows contain the specified value of a column and return this value? What I'm doing and theoretically should work in my mind: PHP: $query = $this->db->query("SELECT COUNT(*) FROM master WHERE faction='$faction';");$number = $query->fetchArray(SQLITE3_ASSOC);return $number;
I've tested and dumped and tested and dumped and all over again. I can't seem to figure it out... Can I get help?
Just tried that. I then call the PHP: count() method on that variable that held the query. I'm now always getting 1...
In SQLite3 extension, every time you fetchArray() it returns a new result row. You should while(is_array($row = fetchArray())).
Remember that the first thing to do when you make a plugin (or other things) with arrays, strings, database values, ... is to print the output
num_rows method: $result = $this->db->query("SELECT COUNT(*) FROM master WHERE faction='$faction'"); $count = $result->num_rows; $value = $count[0]; or with fetch array method: $result = $this->db->query("SELECT COUNT(*) as count FROM master WHERE faction='$faction'"); $count = $result->fetchArray(); $value = $count['count'];