开发者

sql COUNT function returns an array instead of mysqli object?

I want to count some rows in my database and I'm using the following code:

              开发者_如何学C  $tagname = Person;
                $query = "SELECT COUNT(thread_tag_map.tag_id) AS tagcount
                        FROM tags, thread_tag_map
                        WHERE thread_tag_map.tag_id = tags.id
                        AND tags.name = '$tagname'";

                $result = $this->do_query($query);


                return $result;

When I use print_r($result) it shows an associative array Array ( [tagcount] => 3 ).

Shouldn't it be a mysqli object that I have to extract using mysqli_fetch_assoc?

Could someone explain?


Count returns just a number, but you are executing a sql select statement and this will return something like a rowset, i.e. a bunch of rows (in your case 1) with an element for each column (in you case 1).

The exact details depend on the programming language an api you are using.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜