Welcome Guest, Not a member yet? Register   Sign In
how to access the count(*) property?
#7

[eluser]Phil Sturgeon[/eluser]
[quote author="sandeep nami" date="1264164839"]You can use these functions and get the result

$query = $this->db->query('SELECT count(*),country,city,zip from country_location ');
$res=$query->result_array();
echo $res[0]['count(*)'];[/quote]

What in the hell is that?

Use row_array() instead of result, and give your count an alias. Or use the proper methods count_all_results().

http://ellislab.com/codeigniter/user-gui...ecord.html

Code:
echo $this->db->count_all_results('my_table');
// Produces an integer, like 25

$this->db->like('title', 'match');
$this->db->from('my_table');
echo $this->db->count_all_results();
// Produces an integer, like 17

Alternatively if you want to return information and the count, do your normal selecting and use $query->num_rows();

Code:
$this->db->select('name, address, telephone');
$query = $this->db->get('table_name');

$row = $query->row()

$name = $row->name;
$address = $row->address;
$phone = $row->telephone;

$quantity = $query->num_rows();

Come on guys its all in the documentation.


Messages In This Thread
how to access the count(*) property? - by El Forum - 01-21-2010, 11:45 PM
how to access the count(*) property? - by El Forum - 01-22-2010, 12:25 AM
how to access the count(*) property? - by El Forum - 01-22-2010, 12:53 AM
how to access the count(*) property? - by El Forum - 01-22-2010, 12:56 AM
how to access the count(*) property? - by El Forum - 01-22-2010, 12:58 AM
how to access the count(*) property? - by El Forum - 01-22-2010, 03:33 AM
how to access the count(*) property? - by El Forum - 01-22-2010, 04:02 AM
how to access the count(*) property? - by El Forum - 01-22-2010, 07:09 AM
how to access the count(*) property? - by El Forum - 01-28-2010, 08:40 PM
how to access the count(*) property? - by El Forum - 01-28-2010, 09:11 PM
how to access the count(*) property? - by El Forum - 01-28-2010, 09:58 PM
how to access the count(*) property? - by El Forum - 01-29-2010, 12:31 AM
how to access the count(*) property? - by El Forum - 01-29-2010, 03:35 AM
how to access the count(*) property? - by El Forum - 01-29-2010, 04:18 AM
how to access the count(*) property? - by El Forum - 02-07-2010, 06:59 PM



Theme © iAndrew 2016 - Forum software by © MyBB