I need to get the count of each countries by the database.
Here my coding is
$query = $this->db->query("SELECT country FROM list");
echo"<pre>"; print_r($query->result());
The select query returns object as result and array_count_values need array in the parameter
So how can I use array_count_values to dynamically pass values in CodeIgniter.
Try this:
SELECT country, Count(*) FROM list GROUP BY country
Also you can find a full and detailed answer here
SELECT
country,
count(country) as `Total`
FROM list
GROUP BY country
you can following code
function fun_name()
{
$this->db->where('id !=',0);// like this you can set conditions
return $this->db->count_all_results('table_name');
}
You can use num_row()
function for this
$this->db->select('country');
$this->db->from('list');
$query = $this->db->get();
echo $query->num_rows(); // this will print the count of all countries
echo"<pre>"; print_r($query->result()); // this can be used for fetching countries name(else)
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.