CodeIgniter Forums
[Solved!] - HELP!: mysql result from COUNT(*) query - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: [Solved!] - HELP!: mysql result from COUNT(*) query (/showthread.php?tid=2300)



[Solved!] - HELP!: mysql result from COUNT(*) query - El Forum - 07-28-2007

[eluser]gunter[/eluser]
I want know how many rows have parentid = '38'...


Code:
$sql = "SELECT COUNT(*) FROM s3album WHERE parentid = '38'";
        $query = $this->db->query($sql);
        $result = $query->row();
        print_r($result);
I am getting this:
Code:
stdClass Object ( [COUNT(*)] => 2 )

how can I get the result?
with echo $result->?????


[Solved!] - HELP!: mysql result from COUNT(*) query - El Forum - 07-28-2007

[eluser]座頭市[/eluser]
Try this:
Code:
$sql = <<<ENDSQL
SELECT COUNT(*) AS count
FROM s3album
WHERE parent_id = 38
LIMIT 1
ENDSQL;

$query = $this->db->query($sql);
$result = $query->row();

echo $result->count;



[Solved!] - HELP!: mysql result from COUNT(*) query - El Forum - 07-28-2007

[eluser]gunter[/eluser]
Yippie! :-) Thanks!!!! Thats it!


[Solved!] - HELP!: mysql result from COUNT(*) query - El Forum - 07-29-2007

[eluser]Crafter[/eluser]
You could lose the LIMIT clause without a performance impact.