public function dcount($column, $table, $where = '', $replacements = '', $cache = false, $highlight = false) {

        // run the query
        $this->query('

            SELECT
                COUNT(' . $column . ') AS counted
            FROM
                ' . $this->_escape($table) .
            ($where != '' ? ' WHERE ' . $where : '') . '

        ', $replacements, $cache, false, $highlight);

        // if query was executed successfully and one or more records were returned
        if (isset($this->last_result) && $this->last_result !== false && $this->returned_rows > 0) {

            // fetch the result
            $row = $this->fetch_assoc();

            // return the result
            return $row['counted'];

        }

        // if error or no records
        return false;

    }
public function dcount($column, $table, $where = '', $replacements = '', $cache = false, $highlight = false) {

        // run the query
        $this->query('

            SELECT
                COUNT(' . $column . ') AS counted
            FROM
                ' . $this->_escape($table) .
            ($where != '' ? ' WHERE ' . $where : '') . '

        ', $replacements, $cache, false, $highlight);

        // if query was executed successfully and one or more records were returned
        if (isset($this->last_result) && $this->last_result !== false && $this->returned_rows > 0) {

            // fetch the result
            $row = $this->fetch_assoc();

            // return the result
            return $row['counted'];

        }

        // if error or no records
        return false;

    }
public function dcount ( $ column , $ table , $ where = '' , $ replacements = '' , $ cache = false , $ highlight = false ) { // run the query $ this -> query ( '

            SELECT
                COUNT(' . $ column . ') AS counted
            FROM
                ' . $ this -> _escape ( $ table ) . ( $ where != '' ? ' WHERE ' . $ where : '' ) . '

        ' , $ replacements , $ cache , false , $ highlight ) ; // if query was executed successfully and one or more records were returned if ( isset ( $ this -> last_result ) && $ this -> last_result !== false && $ this -> returned_rows > 0 ) { // fetch the result $ row = $ this -> fetch_assoc ( ) ; // return the result return $ row [ 'counted' ] ; } // if error or no records return false ; }
Counts the values in a column of a table.

<code>
// count male users
$male = $db->dcount('id', 'users', 'gender = "M"');

// when working with variables you should use the following syntax
// this way you will stay clear of SQL injections
$users = $db->dcount('id', 'users', 'gender = ?', array($gender));
</code>

@param  string  $column         Name of the column in which to do the counting.

@param  string  $table          Name of the table containing the column.

<i>May also be given like databasename.tablename if a database was not explicitly
selected with the {@link connect()} or {@link select_database()} methods prior to
calling this method.</i>

@param  string  $where          (Optional) A MySQL WHERE clause (without the WHERE keyword).

Default is "" (an empty string).

@param  array   $replacements   (Optional) An array with as many items as the total parameter markers ("?", question
marks) in <i>$where</i>. Each item will be automatically {@link escape()}-ed and
will replace the corresponding "?". Can also include an array as an item, case in
which each value from the array will automatically {@link escape()}-ed and then
concatenated with the other elements from the array - useful when using <i>WHERE
column IN (?)</i> conditions. See second example {@link query here}.

Default is "" (an empty string).

@param  mixed   $cache          (Optional) Instructs the library on whether it should cache the query's results
or not. Can be either FALSE - meaning no caching - or an integer representing the
number of seconds after which the cache will be considered expired and the query
executed again.

The caching method is specified by the value of the {@link caching_method} property.

Default is FALSE.

@param  boolean $highlight      (Optional) If set to TRUE the debugging console will be opened automatically
and the query will be shown - really useful for quick and easy debugging.

Default is FALSE.

@return mixed                   Returns the number of counted records or FALSE if no records matching the given
criteria (if any) were found. It also returns FALSE if there are no records in
the table or if there was an error.

<i>This method may return boolean FALSE but may also return a non-boolean value
which evaluates to FALSE, such as 0. Use the === operator for testing the return
value of this method.</i>
Counts the values in a column of a table .